Hi I'm using Spritekit and Swift, and I'm doing a couple of camera movements and other things based on the user's movement of their finger on the screen.
IN SUMMARY, my problem is that TouchesMoved is not updating consistently, and changes its consistency between taps. All other methods like Update() are updating consistently even when TouchesMoved isn't.
It works perfectly smooth half of the time, but on occasion will begin lagging in regards to anything that is being directly affected by the TouchesMoved method. Here is some of my code:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches{
var positionInScene = touch.location(in: self.view)
//Some arithmetic for calculating length (nothing complex or long)
camera.setScale(length)
}
}
The "lag" only comes or goes between touches.
It also usually comes in bursts. If it's going to lag, it usually does it in a grouping of 10 or more touches, and vice versa. Sometimes the lag comes on the first click of the game, sometimes it takes 50 to get it to show up.
Note that nothing else in the game is lagging even if the touch movement is lagging (not to mention everything else is a lot more complex than the touch movement, often times it literally just zooms the camera in and out). The game uses 30% of the CPU, 50 MB of memory, and VERY HIGH power usage.
UPDATE: I did an elapsed time between calls of both the TouchesMoved method, and the Update method. No matter what, the Update method will run in .016 second intervals. TouchesMoved does the same, however when I notice the lag, its because this interval has been doubled for some reason. Why is it that TouchesMoved is receiving update lag, but my other more complex methods are not?
Here's another post that seems to be having a similar problem: Choppy dragging in SpriteKit game
Please for the love of god save me from this abyss! I've been hitting this problem for a month and this is my last hope before scrapping it.
Thanks!