Friday, 15 April 2011

Cocos2d-x 3.2 Physic Engine: Physic Bodies contact not exactly -



Cocos2d-x 3.2 Physic Engine: Physic Bodies contact not exactly -

i'm newbie of cocos2d-x 3.2 physic engine (as cocos2d-x said, engine base of operations on chipmuk). made sample "egg shooting" game of popcap. when detecting contact of 2 eggs, met problem, dynamic 'egg' seems sink static 'egg' when contact event throwed. set eggs:

mass: 10.f physicsshape_material_default applyimpulse (0,900)

this image:

detect contact ball event

auto contactballlistener = eventlistenerphysicscontact::create(); contactballlistener->oncontactbegin = cc_callback_1(ingamescene::oncontactballsbegin, this); _eventdispatcher->addeventlistenerwithscenegraphpriority(contactballlistener, this); ..... bool ingamescene::oncontactballsbegin(physicscontact& contact) { auto obja = contact.getshapea()->getbody()->getnode(); auto objb = contact.getshapeb()->getbody()->getnode(); }

physical setup

if (group == ballgrouptarget) { //green ball body->setcategorybitmask(0xfffffff0); body->setcontacttestbitmask(0x0000000f); body->setcollisionbitmask(0xffffffff); } else if (group == ballgroupshooting){ //pink ball body->setcontacttestbitmask(0xffffffff); body->setgravityenable(false); }

can help me solve problem?

thanks lot!

bool ingamescene::oncontactballsbegin(physicscontact& contact)

this method should homecoming bool. yours doesn't homecoming anything. pretty sure compiler complains that. not sure c++ defaults to, might homecoming garbage.

return true if want bodies collide, homecoming false if should pass through 1 another.

cocos2d-x game-physics cocos2d-x-3.0

No comments:

Post a Comment