Sometimes randomely my ContactA or B return NULL pointer. Any ideas why
//WHEN TWO PHYSICS OBJECTS COLLIDE FUCNTION - DANIEL
bool FirstWorld::onContactBegin(cocos2d::PhysicsContact &contact)
{
PhysicsBody *contactA = contact.getShapeA()->getBody();
PhysicsBody *contactB = contact.getShapeB()->getBody();
//CHECK WALL AND VEHICLE COLLISION
if (contactA->getCollisionBitmask() == 1 && contactB->getCollisionBitmask() == 2)
{
if (contactA == playerVehicleObject->getPhysicsBody()) { playerVehicleObject->setSpeed(140); }
return true;
}
else if (contactA->getCollisionBitmask() == 2 && contactB->getCollisionBitmask() == 1)
{
if (contactB == playerVehicleObject->getPhysicsBody()) { playerVehicleObject->setSpeed(140); }
return true;
}
if (contactA->getCollisionBitmask() == 2 && contactB->getCollisionBitmask() == 3)
{
this->removeChild(contactB->getNode(), true);
return true;
}
else if (contactA->getCollisionBitmask() == 3 && contactB->getCollisionBitmask() == 2)
{
cocos2d::Sprite* boom = Sprite::create("TrackOne/WayPoint.png");
boom->setPosition(contactA->getNode()->getPosition());//HERE SOMETIMES NULL
this->addChild(boom, 0);
this->removeChild(contactA->getNode(), true);
return true;
}
return true;
};
Also in this contact function when i use “this->addChild(particles);”, Its seems to add to my vehicle layer. Doesn’t this just add to scene. Why it trails along with my vehicle ?