Add Body:getFixture.

Convenience method to get the first Fixture attached to the body.
This commit is contained in:
Sasha Szpakowski
2023-10-04 20:00:44 -03:00
parent 51b439822b
commit 2702004bb2
3 changed files with 30 additions and 0 deletions
+13
View File
@@ -461,6 +461,19 @@ World *Body::getWorld() const
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
{
lua_newtable(L);
+5
View File
@@ -390,6 +390,11 @@ public:
*/
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.
* @return An array of Fixtures.
+12
View File
@@ -599,6 +599,17 @@ int w_Body_getWorld(lua_State *L)
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)
{
Body *t = luax_checkbody(L, 1);
@@ -713,6 +724,7 @@ static const luaL_Reg w_Body_functions[] =
{ "isFixedRotation", w_Body_isFixedRotation },
{ "isTouching", w_Body_isTouching },
{ "getWorld", w_Body_getWorld },
{ "getFixture", w_Body_getFixture },
{ "getFixtures", w_Body_getFixtures },
{ "getJoints", w_Body_getJoints },
{ "getContacts", w_Body_getContacts },