my problem simple, can't fix it.
i have radar rotating , have player moving joystick
well, want detect collision between radar , player. works when both moving doesn't when radar moving , player not.
here have code detect , how works:
//moves radar [self schedule:@selector(loopradar) interval: 12]; //moves player joystick body->setlinearvelocity(b2vec2(scaledvelocity.x*dt, scaledvelocity.y*dt)); actor.position = ccp(body->getposition().x * ptm_ratio, body->getposition().y * ptm_ratio); // detects collision between radar , player std::vector<mycontact>::iterator pos; for(pos = _contactlistener->_contacts.begin(); pos != _contactlistener->_contacts.end(); ++pos) { mycontact contact = *pos; if ((contact.fixturea == radarbody->getfixturelist() && contact.fixtureb == body->getfixturelist()) || (contact.fixturea == body->getfixturelist() && contact.fixtureb == radarbody->getfixturelist())) { //do game on } } //ends collision
mycontactlistener class:
#import "mycontactlistener.h" mycontactlistener::mycontactlistener() : _contacts() { } mycontactlistener::~mycontactlistener() { } void mycontactlistener::begincontact(b2contact* contact) { // need copy out data because b2contact passed in // reused. mycontact mycontact = { contact->getfixturea(), contact->getfixtureb() }; _contacts.push_back(mycontact); } void mycontactlistener::endcontact(b2contact* contact) { mycontact mycontact = { contact->getfixturea(), contact->getfixtureb() }; std::vector<mycontact>::iterator pos; pos = std::find(_contacts.begin(), _contacts.end(), mycontact); if (pos != _contacts.end()) { _contacts.erase(pos); } } void mycontactlistener::presolve(b2contact* contact, const b2manifold* oldmanifold) { } void mycontactlistener::postsolve(b2contact* contact, const b2contactimpulse* impulse) { }
so, problem when radar goes through player , player isn't moving, doesn't detect collision, when both moving works perfectly.
any tips? thank much!
worked adding these lines "learncocos2d" said, setting both bodies awake
body->setawake(true); radarbody->setawake(true);
thank much!
Comments
Post a Comment