title: How do I interact with multiple sprites in Swift?
body: <p>I am currently working on a game where I want to swipe the sprites left and right as they fall down from the top of the screen. However, I am only able to interact with the most recent sprite generated. All the other sprites I am unable to touch. I am unsure what the problem is but I would appreciate any help. Thanks! I will put the code below if any one is interested in seeing what I am taking about.</p>
  
  <pre><code>import SpriteKit
  class GameScene: SKScene {
  
  var sprite: SKSpriteNode!
  var touchPoint: CGPoint = CGPoint()
  var touching: Bool = false
  
  override func didMoveToView(view: SKView) {
      physicsWorld.gravity = CGVectorMake(0, -0.999)
      sprite = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 60, height: 60))
      sprite.physicsBody = SKPhysicsBody(rectangleOfSize: sprite.size)
      sprite.position = CGPoint(x: frame.size.width/2.0, y: frame.size.height)
  
      runAction(SKAction.repeatActionForever(
          SKAction.sequence([SKAction.runBlock(addMonster), SKAction.waitForDuration(1.0)])))
  
  }
  
  func addMonster() {
  
      sprite = SKSpriteNode(color: UIColor.redColor(), size: CGSize(width: 60, height: 60))
      sprite.physicsBody = SKPhysicsBody(rectangleOfSize: sprite.size)
      sprite.position = CGPoint(x: frame.size.width/2.0, y: frame.size.height)
  
      addChild(sprite)
  
  }
  
  override func touchesBegan(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
      let touch = touches.first! as UITouch
      let location = touch.locationInNode(self)
      if sprite.frame.contains(location) {
          touchPoint = location
          touching = true
      }
  }
  
  
  override func touchesMoved(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
      for touch: AnyObject in touches {let touch = touches.first! as UITouch
      let location = touch.locationInNode(self)
          touchPoint = location}
  }
  
  
  
  override func touchesEnded(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?) {
      touching = false
  }
  
  override func update(currentTime: CFTimeInterval) {
      if touching {
          let dt:CGFloat = 1.0/60.0
          let distance = CGVector(dx: touchPoint.x-sprite.position.x, dy: touchPoint.y-sprite.position.y)
          let velocity = CGVector(dx: distance.dx/dt, dy: distance.dy/dt)
          sprite.physicsBody!.velocity=velocity
      }
  }
   }
  </code></pre>