3

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!

Community
  • 1
  • 1
Marshall D
  • 454
  • 3
  • 20
  • 1
    Profile it and post your findings. – Alexander Nov 28 '16 at 05:34
  • @AlexanderMomchliov I have no idea how to do that - can you give me a link explaining the process for that, or point me in the right direction? – Marshall D Nov 28 '16 at 21:37
  • https://www.raywenderlich.com/97886/instruments-tutorial-with-swift-getting-started – Alexander Nov 28 '16 at 21:51
  • Discussing performance without a profile is like navigating a new place without a map. You can't make many useful observations beyond the most obvious and least useful ones – Alexander Nov 28 '16 at 21:52
  • @AlexanderMomchliov I added in something I found from profiling it. I'm not 100% sure what Im doing, so if I didn't do it correctly please tell me. thanks – Marshall D Nov 29 '16 at 00:35
  • That method is a library method that (eventually) calls your code. Expand out that call tree until you see your actual user code being called, and how much time that's using – Alexander Nov 29 '16 at 00:37
  • @AlexanderMomchliov I added it in completely expanded. Nothing really looks like my code, is what I just added the user code? – Marshall D Nov 29 '16 at 00:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/129297/discussion-between-alexander-momchliov-and-marshalld). – Alexander Nov 29 '16 at 00:48
  • A touch event has a timestamp. If the timing between events is important to you, look at the timestamp, not the clock. – matt Nov 30 '16 at 02:26
  • 1
    @matt wont that just give me a different way of saying "hey, this isn't updating properly" – Marshall D Nov 30 '16 at 03:06

0 Answers0