6

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?

  • gesture recognizers maybe but to tell more you should add your touch setup and events code – CodeSmile Jun 14 '14 at 19:44
  • are you trying to drag sprites around that are still dynamic physics nodes? That plus fine grained physics detection will normally grind you to a halt. But as stated above, code would help. – Cooper Buckingham Jun 14 '14 at 20:02
  • Updated with more info! – Kaylee Calderolla Jun 15 '14 at 15:29
  • I have similar problem and wondering if this is the question of changing sprites position instantly or in the update: method. Have you found anything about this? – Krzysztof Przygoda Jan 28 '15 at 07:39
  • 1
    I haven't worked on this project for a while, but I was doing everything in the update: method. – Kaylee Calderolla Jan 28 '15 at 18:26
  • @GiorgioCalderolla - my current investigation leads me that way. Do you remember if it did any improve in your project? – Krzysztof Przygoda Jan 29 '15 at 20:22
  • @KrzysztofPrzygoda nothing I tried helped in any way :/ I'll post here if I make progress. – Kaylee Calderolla Feb 02 '15 at 04:19
  • I'm running into this exact problem and it's driving me insane... long shot but @KrzysztofPrzygoda or Giorgio any luck resolving this? – kmurph79 Dec 02 '15 at 19:06
  • 1
    Nope, but I think this is UIResponder issue rather than Sprite Kit. – Krzysztof Przygoda Dec 02 '15 at 21:25
  • @KrzysztofPrzygoda ok, thanks. very frustrating that this issue hasn't been resolved since OP posted this ~1.5 years ago. i'll submit a bug report to Apple and see if that goes anywhere – kmurph79 Dec 03 '15 at 00:49
  • 1
    A much serious bugs I submitted hasn't been resolved yet and they ask some absurd questions after a year instead of investigating them. So I refrain from bug reporting for them. – Krzysztof Przygoda Dec 03 '15 at 18:56
  • 1
    @kmurph79 I haven't worked on that project since, so no progress from me either. – Kaylee Calderolla Dec 03 '15 at 23:02
  • @KrzysztofPrzygoda and Giorgio - am I crazy or did Apple fix this? – kmurph79 Oct 24 '16 at 01:49
  • @kmurph79 no idea! – Kaylee Calderolla Oct 24 '16 at 01:53
  • @kmurph79 Unfortunately, me neither :/ They are so ignorant in bugfixing that they can come back after a year asking to make a sample project for them. – Krzysztof Przygoda Oct 24 '16 at 10:32
  • @KrzysztofPrzygoda and Giorgio Is there any way you can think to work around this? I have to basically throw out my project if I can't fix this. I'm not using touchesMoved in the same way however - I'm simply asking if there's a way to cheat my way into getting touchesMoved to update consistently – Marshall D Dec 02 '16 at 04:07
  • @MarshallD - Unfortunately, I abandoned Apple for a while... However you can either send bug report or/and play with **SpriteKit Update Loop** as a last resort, i.e. update sprite position in more controlled manner using loop methods (like `didFinishUpdate` or earlier). Anyway, I still think it is the problem of UIResponder because I've also found that dragging process is sometimes delayed by a fraction of second. On the contrary, many apps seem to handle it correctly, so maybe there is some missing link I don't know and couldn't find also... – Krzysztof Przygoda Dec 02 '16 at 14:38
  • No idea other than to file radars and get an answer from the framework authors. – Kaylee Calderolla Dec 02 '16 at 15:59
  • @KrzysztofPrzygoda and Giorgio... shameless plug but [this](https://itunes.apple.com/us/app/dr.-kodama/id1060934796?mt=8) is the game I created. For my purposes, this issue has been significantly alleviated or solved... dragging speed appears to maintain its snappiness no longer how long I play. – kmurph79 Dec 27 '16 at 22:11

0 Answers0