mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Add type to Body constructor (defaults to "static")
--HG-- branch : box2d-update
This commit is contained in:
@@ -33,13 +33,14 @@ namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Body::Body(World * world, b2Vec2 p)
|
||||
Body::Body(World * world, b2Vec2 p, Body::Type type)
|
||||
: world(world)
|
||||
{
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
body = world->world->CreateBody(&def);
|
||||
this->setType(type);
|
||||
}
|
||||
|
||||
Body::~Body()
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace box2d
|
||||
/**
|
||||
* Create a Body at position p.
|
||||
**/
|
||||
Body(World * world, b2Vec2 p);
|
||||
Body(World * world, b2Vec2 p, Type type);
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@ namespace box2d
|
||||
return new World(b2Vec2(gx, gy), sleep);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world, float x, float y)
|
||||
Body * Physics::newBody(World * world, float x, float y, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(x, y));
|
||||
return new Body(world, b2Vec2(x, y), type);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world)
|
||||
Body * Physics::newBody(World * world, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(0, 0));
|
||||
return new Body(world, b2Vec2(0, 0), type);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(float radius)
|
||||
|
||||
@@ -81,14 +81,16 @@ namespace box2d
|
||||
* @param world The world to create the Body in.
|
||||
* @param x The position along the x-axis.
|
||||
* @param x The position along the y-axis.
|
||||
* @param type The type of body to create.
|
||||
**/
|
||||
Body * newBody(World * world, float x, float y);
|
||||
Body * newBody(World * world, float x, float y, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new Body at (0, 0)
|
||||
* @param world The world to create the Body in.
|
||||
* @param type The type of Body to create.
|
||||
**/
|
||||
Body * newBody(World * world);
|
||||
Body * newBody(World * world, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (0, 0).
|
||||
|
||||
@@ -47,7 +47,10 @@ namespace box2d
|
||||
World * world = luax_checktype<World>(L, 1, "World", PHYSICS_WORLD_T);
|
||||
float x = (float)luaL_optnumber(L, 2, 0.0);
|
||||
float y = (float)luaL_optnumber(L, 3, 0.0);
|
||||
Body * body = instance->newBody(world, x, y);
|
||||
const char * type = luaL_optstring(L, 4, "static");
|
||||
Body::Type bodyType;
|
||||
Body::getConstant(type, bodyType);
|
||||
Body * body = instance->newBody(world, x, y, bodyType);
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user