Hello guys.
I have below method:
bool HelloWorld::onContactBegin(cocos2d::PhysicsContact& contact) {
int objectATag = contact.getShapeA()->getTag();
int objectBTag = contact.getShapeB()->getTag();
auto nodeA = contact.getShapeA()->getBody()->getNode();
auto nodeB = contact.getShapeB()->getBody()->getNode();
nodeA->setPosition(600, 400);
return true;
}
However,
nodeA->setPosition(600, 400);
does not work. I can remove and add physic body, change every property related to physic body, sprite which attached to physic body move along with it, but I am not able to move the sprite to any particular position.
Do you have any suggestion?
Thanks in advance
If you print the nodeA->getPosition() right after, does it show the updated position?
Could it be that the physics are overwriding the custom position you’re setting and its effectively being ignored the next time you’re running the physics loop? Just a guess.
I logged it. it shows desired position however nothing happens and “nodeA” does not move to that position. I think that your idea is right,something is overriding the position, but, how should I prohibit that?
actualy I have another question. Is there any way to add child in runtime?
you can add childs anytime you want. (node->addChild(otherNode))
You sure ur nodeA object is pointing towards ur actual node?
It could be the other object of the collision. (plus add a nullpointer check if you will use bodys without user objects in the future.)
when I add child I face fatal error of android.
The node is correct cause I logged it and changing physic body of it, not once but multiple times.
Finally I solved it. Just disabled physic body and make sprite invisible 
What version of cocos2d-x are you using?