Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKSPriteNode position changes to 0,0 for no reason

Tags:

ios

sprite-kit

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?

like image 548
Dvole Avatar asked Dec 03 '13 18:12

Dvole


1 Answers

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.

like image 55
Dvole Avatar answered Nov 23 '22 23:11

Dvole