2

I am currently developing a game where the user should only be able to touch with one finger at a time. I am using SKScene and have tried searching for ways to disable the multi-touch functionality, but nothing turned up. I was thinking of just manually calling "return" on all touches between touchesBegan() and touchesEnded() were called, but that method is flawed too (SpriteKit SKScene missing touchesEnded).

So my question is: How can I only allow one touch at a time in SKScene?

Community
  • 1
  • 1
Jacob R
  • 1,243
  • 1
  • 16
  • 23

3 Answers3

7

SKView inherits from UIView, so, in didMoveToView add:

self.view.multipleTouchEnabled = NO;
Joaquin Llaneza
  • 451
  • 2
  • 15
0

Ironically enough, after days of finding nothing I came up with a hack right after posting this question. Notice though, that it is a hack, and it is not optimal, so I am still looking for better suggestions. The hack is as follows:

Inside touchesBegan(), replace:

    for touch: AnyObject in touches {
        // Whatever is being done on touch
    }

with:

    for touch: AnyObject in touches {
        if(CACurrentMediaTime()-lastTouchDate < 0.1) {
            return;
        }
        lastTouchDate = CACurrentMediaTime();
        // Whatever is being done on touch
    }

This way, only the first touch will be registered, when multiple touches are coming in at once, or right after each other. if(CACurrentMediaTime()-lastTouchDate < 0.1) checks if it is less than 0.1 seconds since the last touch was accepted.

Jacob R
  • 1,243
  • 1
  • 16
  • 23
0

thats worked for me

self.view?.isMultipleTouchEnabled = false