Search code examples
sprite-kittvos

How to detect touches in Sprite Kit tvOS


I have an iOS Sprite Kit app which has a few nodes moving around and you have to tap on the correct node to get a point. I've used this method:

- (void)touchesBegin:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    SKNode *targetNode = [self nodeAtPoint:[touch locationInNode:self]];
    // Codes to check whether the user tapped the correct nodes goes here.
}

Now I wants to port my app to tvOS. Everything works fine but the touches. But how can you detect touches with it?


Solution

  • There is no equivalent to "touching" on tvOS because the user is using either a remote or a game controller.

    You will need to design and implement an alternative user interface to provide visual feedback and react to actions on the remote (or game controller).

    Apple recommends against using a "cursor" approach so you will need to be creative to find a solution that meets your game's requirements. Given that thumb movements on the remote's touch area are not as reactive vertically as they are horizontally, a cursor is very difficult to control for users.

    If your game can have a notion of "Focus", there may be some workable solution. Otherwise, the port to tvOS will be a challenge.