title: How to make a Button continually call a function when held down (SpriteKit)
body: <p>I'm making a game using sprite kit and I want my Character to move across the screen when you hold down the left/right move button. The problem is that he only moves when the button is tapped, not held. I have looked everywhere for a solution but nothing seems to work!</p>
  
  <p>Here's my code;</p>
  
  <pre><code>class Button: SKNode
  {
     var defaultButton: SKSpriteNode // defualt state
     var activeButton: SKSpriteNode  // active state
  
     var timer = Timer()
  
     var action: () -&gt; Void
  
     //default constructor
     init(defaultButtonImage: String, activeButtonImage: String, buttonAction: @escaping () -&gt; Void )
     {
        //get the images for both button states
        defaultButton = SKSpriteNode(imageNamed: defaultButtonImage)
        activeButton = SKSpriteNode(imageNamed: activeButtonImage)
  
        //hide it while not in use
        activeButton.isHidden = true 
        action = buttonAction
  
        super.init()
  
        isUserInteractionEnabled = true
  
        addChild(defaultButton)
        addChild(activeButton)    
     }
  
     //When user touches button
     override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?)
     {
        action()
  
        //using timer to repeatedly call action, doesnt seem to work...
        self.timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(getter: Button.action), userInfo: nil, repeats: true)
  
        //swtich the image of our button
        activeButton.isHidden = false
        defaultButton.isHidden = true
  
     }
  
     code..........
  </code></pre>
  
  <p>In my game scene...</p>
  
  <pre><code>// *** RIGHT MOVEMENT ***
        let rightMovementbutton = Button(defaultButtonImage: "arrow", activeButtonImage: "arrowActive", buttonAction:
        {
  
           let moveAction = SKAction.moveBy(x: 15, y: 0, duration: 0.1)
           self.player.run(moveAction)
  
  
        })
  </code></pre>