Wait for touch?

` I'm trying to code something so the program waits for the screen to be touched. after the screen is touched, I want to change text using a SKLabelNode.


Here's an example of what I'm trying to do:


1. Wait for touch

2. Change text

3. Wait for touch

4. Change text


I want this to repeat several times before going to a different segment. I'll also need to use touches in other parts of the program.

Replies

What do you mean "wait for touch" ?


If you do no thing, then the program will seem to wait.

And you code the action associate with the touch, then program will appear to have waited.


Do you mean that no other action than the touch would be possible ? (take care on user experience doing so)

The way I would do this:

- have a global status for the app, with an observer

var waitForTouch: Bool = false {
     didset {
     }
}

When you need, you set to true

In the didset, you set isUserInteractionEnabled to false or true (opposite of isUserInteractionEnabled) for all objects of the current view, except the ones for which you authorize touches

When you have done with the touches, restore isUserInteractionEnabled to true