Touch Began, how to get all the touches, not just the first or last?

In SpriteKit SKSpriteNodes and other visible nodes, touch responses in these nodes are often performed as follows:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

        if let touch = touches.first {...
 // do something with the touch location that now in touch
// etc

Itโ€™s all great, but what if I want to get information about touching every and every touch inside this (letโ€™s imagine ...) SKSpriteNode?

= touchhes.first limits the conditional response to only the first touch inside this SKSpriteNode. How it is done for all the strokes in this SKSpriteNode, so that everyone has their own location or something else that he received and transfers.

I know. Stupid question. I am that guy. I just donโ€™t see how this is done.

+4
2

, multipleTouchEnabled true.

mySprite.multipleTouchEnabled = true

, touchesBegan:event: UITouch, Set (a.k.a. ) UITouch.

, , () , .

for touch in touches {
  // do something with the touch object
  print(touch.location(mySKNodeObject))
}
+8

, Commscheck, , node :

for _touch in touches {
   let aTouch = _touch.location(in: self)
   if nodes(at: aTouch).contains(desiredNode) {
     print("desired node found")
     desireNode.doSomething()

     // You can also do, 
     // if desiredNode.contains(aTouch) {
   }
}

SKScene.nodes, .contains, nodes - ; SKScene SKEffectsNode, SKNode.., SKScene , nodes ...

open func nodes(at p: CGPoint) -> [SKNode]

"SKScene", ".". .

, node, SKNode ( node) touches_.

, , :)

+2

Source: https://habr.com/ru/post/1662489/


All Articles