I'm adding an old-school high-score entry screen to my game, in which the users tap each letter to enter their name.
Each letter, symbol or phrase ('DEL', 'SP' etc) is a single SKLabelNode
and it's very difficult to tap on the ',' and '.' characters and some of the symbols though. Each tap is detected via the usual touchesBegan
To make detention easier I plan on placing a larger node behind each letter and update touchesBegan
to either detect a touch on the label itself or on this other label, in which case just use the child node for the touch (which will be the letter or phrase).
Before I do this I was wondering if there is an easy way to achieve what I want, possible by detecting the nearest SKLabelNode
to a touch etc.
Just building on what @KnightOfDragon said, I would just create a subclass of SKSpriteNode for each key. That way it keeps your code objectified and pretty!
There is so much more that can be done here, but I whipped this up in a hurry. It doesn't have all the letters and it doesn't know how to handle del, space, return, but I figured your code already knew what to do with those.
The Key class uses a protocol to send down which key was pushed, so you don't have to worry about capturing each key area in the scene
So I entered the rest of the keys and added some blank filler options for spacing. I don't have the same font as you but it looks pretty cool