title: How to make a shot in spritekit?
body: <p>I have created a method called <code>attackButton</code>. Inside this function, I wrote this way in order to fire a shot. <code>hero</code> below is a node where I want a shot to be born.</p>
  
  <pre><code>func attackButton() {
  
      shot.physicsBody = SKPhysicsBody(edgeLoopFromRect: shot.frame)
      shot.position = CGPointMake(hero.position.x, hero.position.y)
      shot.physicsBody?.categoryBitMask = shootingCategory
      shot.physicsBody?.contactTestBitMask = enemyCategory
      addChild(shot)
  
      let run = SKAction.moveByX(2, y: 0, duration: 1)
      shot.runAction(run)
  }
  </code></pre>
  
  <p>The shot node is displayed on the scene, but the node never moves and after a button is pressed twice, an error occurs. I guess it is because of lack of code which is <code>removeFromSuperview()</code>, or <code>removeFromParent</code>, though I am unsure about that. So, why does the node not move to x direction? Should I write this inside the <code>update(currentTime: CFTimeInterval)</code> method? Though to me this sound a bit too technical. This <code>attackButton</code> is detected by being written in the <code>touchesBegan(touches: Set&lt;UITouch&gt;, withEvent event: UIEvent?)</code>by specifying the name of the node like this: </p>
  
  <pre><code>for touch in touches {
          let location = touch.locationInNode(self)
          let node = self.nodeAtPoint(location)
  
              if node.name == "attackButton" {
                  attackButton()
              }
  
          }
  </code></pre>
  
  <p>If I write this function in the <code>update(currentTime: CFTimeInterval)</code>, how is the method is triggered? I can't figure out as the method does not know if I press the <code>attackButton</code>, because this <code>attackButton</code> is a node and the name of the node has to be specified, right? Maybe what I say does not make sense, but I appreciate if you understand me, and could you give me some code that enables firing a shot? Thanks!</p>