I create an SKSpriteNode
in didBeginContact
method with location of contact:
CommonBox *boxTwo = [[CommonBox alloc] initWithTexture:[self.mainAtlas textureNamed:@"box07"]];
boxTwo.name = @"regularBox";
boxTwo.position = contact.contactPoint;
[self addChild:boxTwo];
The position is correct here. Then update method is called and the position of box is magically changed to 0,0 at start of update method, before any code at all is executed. Why is that? No other code is executed between these two events. This is driving me crazy. I tried removing all collision and contact bit masks from this object, but it changes to zeroes anyway. Object is legal and so on.
EDIT: if I remove physics body from that node I will get desired position. But how do I set my position of node if it has physics body?
I found out my mistake - you have to create physics body after you set node position. Setting position after physics body has position doesn't do anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With