mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Add Body:getFixture.
Convenience method to get the first Fixture attached to the body.
This commit is contained in:
@@ -461,6 +461,19 @@ World *Body::getWorld() const
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fixture *Body::getFixture() const
|
||||||
|
{
|
||||||
|
b2Fixture *f = body->GetFixtureList();
|
||||||
|
if (f == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
Fixture *fixture = (Fixture *)(f->GetUserData().pointer);
|
||||||
|
if (!fixture)
|
||||||
|
throw love::Exception("A fixture has escaped Memoizer!");
|
||||||
|
|
||||||
|
return fixture;
|
||||||
|
}
|
||||||
|
|
||||||
int Body::getFixtures(lua_State *L) const
|
int Body::getFixtures(lua_State *L) const
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|||||||
@@ -390,6 +390,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
World *getWorld() const;
|
World *getWorld() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the first Fixture attached to this Body.
|
||||||
|
**/
|
||||||
|
Fixture *getFixture() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of all the Fixtures attached to this Body.
|
* Get an array of all the Fixtures attached to this Body.
|
||||||
* @return An array of Fixtures.
|
* @return An array of Fixtures.
|
||||||
|
|||||||
@@ -599,6 +599,17 @@ int w_Body_getWorld(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Body_getFixture(lua_State *L)
|
||||||
|
{
|
||||||
|
Body *t = luax_checkbody(L, 1);
|
||||||
|
Fixture *f = t->getFixture();
|
||||||
|
if (f)
|
||||||
|
luax_pushtype(L, f);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_Body_getFixtures(lua_State *L)
|
int w_Body_getFixtures(lua_State *L)
|
||||||
{
|
{
|
||||||
Body *t = luax_checkbody(L, 1);
|
Body *t = luax_checkbody(L, 1);
|
||||||
@@ -713,6 +724,7 @@ static const luaL_Reg w_Body_functions[] =
|
|||||||
{ "isFixedRotation", w_Body_isFixedRotation },
|
{ "isFixedRotation", w_Body_isFixedRotation },
|
||||||
{ "isTouching", w_Body_isTouching },
|
{ "isTouching", w_Body_isTouching },
|
||||||
{ "getWorld", w_Body_getWorld },
|
{ "getWorld", w_Body_getWorld },
|
||||||
|
{ "getFixture", w_Body_getFixture },
|
||||||
{ "getFixtures", w_Body_getFixtures },
|
{ "getFixtures", w_Body_getFixtures },
|
||||||
{ "getJoints", w_Body_getJoints },
|
{ "getJoints", w_Body_getJoints },
|
||||||
{ "getContacts", w_Body_getContacts },
|
{ "getContacts", w_Body_getContacts },
|
||||||
|
|||||||
Reference in New Issue
Block a user