I'm working on a simple SpriteKit game (in Swift) with basic physics, which involves dragging and dropping some SKSpriteNodes with touches. The implementation uses touchesBegan, touchesMoved, etc. and updates the position of the touched sprite. Everything works as expected, but:
Good: the game altogether runs at constant 60fps, cpu usage is at about 50%, gpu at 6%
Bad: the dragged sprite is sometimes very choppy (looks like 10fps or similar). Note that by this I mean that all other sprites STILL animate at 60fps even during this problem.
This is because touchesMoved sometimes starts being called more infrequently than the usual 60 times per second. Usually I can drag and drop a few sprites smoothly, and then it starts being choppy and never returns to normal.
This is a simplified version of my touch handling:
override func touchesMoved(touches: NSSet!, withEvent event: UIEvent!) {
if let allTouches = touches.allObjects as? UITouch[] {
for touch in allTouches {
let draggedThing = findDraggedThingForTouch(touch)
draggedThing.dragJoint!.bodyB.node.position = touch.locationInNode(self)
}
}
}
I've tried using gesture recognizers instead of touch events, changing the position of the sprite instead of dragging it via a spring joint, and making the dragged thing not dynamic. All version exhibit the same bug, i.e. after a while, touchesMoved or the gesture recognizer action start firing like 5 times per second instead of 60.
What could cause this?