I'm attempting to build a SpriteKit game which involves levels with physics bodies which can be zoomed in and out on. The physics world is not behaving as I would expect and causing strange things to happen when the zoom level is changed.
The nodes with physics bodies animate and behave as expected. Zooming around the level is handled with a pinch gesture which is adjusting the scale of a single 'world node' which contains all of the game elements. This is a convenient way to handle it as scaling the scene seems to do horrible things, and it will make it easy to add a separate unscaled node for any game interface elements on top of the world node.
The zooming works something like this:
- (void) handlePinchGesture:(UIPinchGestureRecognizer *) gesture {
if (gesture.state == UIGestureRecognizerStateChanged) {
[self.worldNode runAction:[SKAction scaleBy:gesture.scale duration:0.0]];
gesture.scale = 1;
}
}
When at the normal zoom level, everything works great, and visually, everything looks fine at different zoom levels as well. The problem is that when the zoom changes, the physics bodies continue to move at the same speed across the speed not at the same speed relative to other objects. The result is that everything moves much faster when zooming out to see more of the scene.
This seems to be a side effect of the fact that the physics world is connected only to the scene and is not aware of the adjusted scale of the 'world node'. Shouldn't the physics bodies continue moving the nodes at the same speed in their relative spaces though?
Can anyone provide any insight into why SpriteKit behaves the way it does, or how to get around this?