mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add Body:isTouching(otherbody). See issue #1365.
This commit is contained in:
@@ -422,6 +422,22 @@ bool Body::isFixedRotation() const
|
||||
return body->IsFixedRotation();
|
||||
}
|
||||
|
||||
bool Body::isTouching(Body *other) const
|
||||
{
|
||||
const b2ContactEdge *ce = body->GetContactList();
|
||||
b2Body *otherbody = other->body;
|
||||
|
||||
while (ce != nullptr)
|
||||
{
|
||||
if (ce->other == otherbody)
|
||||
return true;
|
||||
|
||||
ce = ce->next;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
World *Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
|
||||
@@ -382,6 +382,8 @@ public:
|
||||
void setFixedRotation(bool fixed);
|
||||
bool isFixedRotation() const;
|
||||
|
||||
bool isTouching(Body *other) const;
|
||||
|
||||
/**
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
|
||||
@@ -522,6 +522,14 @@ int w_Body_isFixedRotation(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Body_isTouching(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
Body *other = luax_checkbody(L, 2);
|
||||
luax_pushboolean(L, t->isTouching(other));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Body_getWorld(lua_State *L)
|
||||
{
|
||||
Body *t = luax_checkbody(L, 1);
|
||||
@@ -655,6 +663,7 @@ static const luaL_Reg w_Body_functions[] =
|
||||
{ "setAwake", w_Body_setAwake },
|
||||
{ "setFixedRotation", w_Body_setFixedRotation },
|
||||
{ "isFixedRotation", w_Body_isFixedRotation },
|
||||
{ "isTouching", w_Body_isTouching },
|
||||
{ "getWorld", w_Body_getWorld },
|
||||
{ "getFixtures", w_Body_getFixtures },
|
||||
{ "getJoints", w_Body_getJoints },
|
||||
|
||||
Reference in New Issue
Block a user