For example if I want to do my own custom animation and move an SKSpriteNode every frame programmatically by x += 10
, will Sprite Kit still apply physics correctly or must I always use SKAction?
Asked
Active
Viewed 1,295 times
2 Answers
4
Manually moving a node with a physics body is possible regardless of how or when you do it. But in any case it's not recommended since it can adversely affect the physics simulation. The node (view) could be out of sync with the position of the body for 1 frame, and you might move the body into a collision which the physics engine will forcibly resolve, causing jumps, jitter, exploding velocities or skipping collisions.
When you use physics, stick to moving the physics body through force, impulse or changing the body velocity directly.

CodeSmile
- 64,284
- 20
- 132
- 217
-
What if we put the code which moves the node into `didSimulatePhysics` method? The node shouldn't be out of sync then – Andrey Gordeev Dec 22 '13 at 07:00
-
2it's going to be out of sync with physics. The physics world has been simulated, now you move the node and body manually which can put it into a collision for the current frame. The collision will only be resolved for the next frame, after which you move the body elsewhere once again. No matter how you do this it'll always be problematic. Use physics entirely or not at all if you want a stable, non-glitching simulation. – CodeSmile Dec 22 '13 at 09:20
2
No, you don't have to use SKAction
to move SKSpriteNode
. This approach works fine for me:
- (void)update:(CFTimeInterval)currentTime {
myNode.position = CGPointMake(myNode.position.x + 0.1,myNode.position.y);
}
All physics work as expected

Andrey Gordeev
- 30,606
- 13
- 135
- 162
-
LearnCocos2D sais otherwise in his answer. Do you think Sprite Kit handles it differently then (I assume) Cocos 2D? – openfrog Dec 21 '13 at 19:04
-
I think it's probably the case that whilst you can move the body in 'update', results may be unpredictable, if you also want the physics engine to move the body. After all, the physics engine has done all these calculations to work out where the body should be, and you go and move it somewhere else! You should be able to come up with a suitable SKAction to perform the movement you're trying to do manually. – Steve Ives Mar 30 '16 at 19:52