c++ - Cocos2d-x PhysicsContact Object Reference -
i'm trying make videogame c++ in cocos2d-x have issue physiccontact.
in gamescene have contact listener check collisions character , objects' physicbody of class item. works fine, want recognize object has collided because want call method of object's class called getthrow().
class item : public cocos2d::layer { public: sprite* itemart; int itemtype; physicsbody* itemcollider; void createart(int type); void getthrow(); item(int type); };
i have tried physiccontact information, first obtain object physicbody , node, obtain object's sprite , @ point don't know how reach object call method.
bool level0::oncontactbegin(physicscontact &contact) { auto bodya = contact.getshapea()->getbody()->getnode(); auto bodyb = contact.getshapeb()->getbody()->getnode(); //here want run bodyb->getthrow() return true; }
i have tried getuserdata() , getuserobject() don't know how call method object pointer.
i don't know if i'm trying incorrectly, appreciate answers.
thanks in advance! (if more details needed tell me, i'm new @ big community)
you need this:
((item*) b->getnode())->getthrow();
Comments
Post a Comment