I'm trying to make a game where the player at certain times draw a pattern on the screen. My solution for this is to add multiple nodes on the screen that are touchable via an extension of SKSpriteNode. When the player touches a node, I want to call touchesmoved, and add all nodes touched to an array. Then, when the player stops touching the screen, I want to match that array to another array, and something happens.
I've been playing around with the updates function and try to run a function each update loop, but it didn't work very well. I've also tried making the gameScene class a delegate of my touchableShapeNode Class, but I struggled to make it work.
class TouchableShapeNode: SKShapeNode {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if (name != nil) {
print("\(name ?? "node") touched")
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if (name != nil) {
print("\(name ?? "node") touched")
}
}
}
My problem is that the only node that gets selected right now is the first node I touch, not the ones the player's finger move over. Right now I'm just printing the name of the touched node.
touchesBegan
to establish the node at the touch. However, why not use touchesMoved` to simply examine the node at each touch location and aadd it to an array? Here's some code that flags a node as 'touched' intouchesBegan
- I think all you'll need to so is to add similar code totouchesMoved
stackoverflow.com/a/56490384/1430420 – Steve Ives