Cocos2d-x with Physics Editor - EventListenerPhysicsContact not fired

0

If I force reset CategoryBitmask and CollisionBitmask in code then contact listener fired. Why not its not work with physics editor…what’s my mistake with physics editor setup ?

Hero, Coins, Bomb - 3 Objects. here Hero must collide with Coins and Bomb.

Here is Code to force set:

PhysicsShapeCache *shapeCache = PhysicsShapeCache::getInstance(); ;
shapeCache->setBodyOnSprite("HeroPhysicsShape", hero);
hero->getPhysicsBody()->setTag(HERO_BODYS_TAG);

//Force Reset
hero->getPhysicsBody()->setCategoryBitmask(0x01);
hero->getPhysicsBody()->setCollisionBitmask(0x05);
hero->getPhysicsBody()->setContactTestBitmask(0xFFFFFFFF);

Coins Code:

PhysicsShapeCache *shapeCache = PhysicsShapeCache::getInstance();
shapeCache->setBodyOnSprite("CoinShape", coin);

coin->getPhysicsBody()->setGravityEnable(false);
coin->getPhysicsBody()->setTag(COIN_BODYS_TAG);

coin->getPhysicsBody()->setCategoryBitmask(0x02);
coin->getPhysicsBody()->setCollisionBitmask(0x01);
coin->getPhysicsBody()->setContactTestBitmask(0x01);
coin->getPhysicsBody()->setDynamic(false);

Contact Listner

auto contactListener = EventListenerPhysicsContact::create();
contactListener->onContactBegin = CC_CALLBACK_1(MGGameScene::onContactBegin, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(contactListener,this);

bool MGGameScene::onContactBegin(cocos2d::PhysicsContact& contact)
{
  // comes here if I force set Bitmask in code.
}

Here is Physics Editor Screenshot. Why collision set in physics editor not working..whats wrong ? enter image description here enter image description here enter image description here

ios
iphone
xcode
cocos2d-x
physicseditor
asked on Stack Overflow Mar 9, 2020 by Guru • edited Mar 9, 2020 by Guru

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0