My game scene ground is made of multiple individual objects (bricks). I want to detect collision with the ground but at the same time ignore the collision instances when the character transitions from a brick to another. At the moment, any code that I write in the onContactEnd collision with the bricks, it gets executed every time the player transitions from a brick to another, despite the bricks being connected with eachother.
So I have the code:
bool GameScene::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ((1 == a->getCollisionBitmask() && 4 == b->getCollisionBitmask()) || (4 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))
{
brickcontact = 1;
return true;
}
}
bool GameScene::onContactEnd(cocos2d::PhysicsContact &contact)
{
PhysicsBody *a = contact.getShapeA()->getBody();
PhysicsBody *b = contact.getShapeB()->getBody();
if ((1 == a->getCollisionBitmask() && 4 == b->getCollisionBitmask()) || (4 == a->getCollisionBitmask() && 1 == b->getCollisionBitmask()))
{
brickcontact = 0;
return true;
}
}
I update the player in an update function depending on the brickcontact value. I want to tell the listener to wait before calling a method if the brickcontact hasn’t been modified in the last 0.2-0.5 seconds or so AND if it’s 0 (basically when I leave the ground AND not being in contact with it for an amount of time).
I feel like this is easy to implement, but I don’t know what to use.