Touch began func saying touch is never used

I have the code below and I am trying to make the pig on my screen move so I added a touch began function.

When I added in the function, it said that touch was never used and that I should replace it with a _. What am I doing wrong?

import SpriteKit
import UIKit

class GameScene: SKScene {
    var porker:Porker!
    var touchLocation = CGFloat()

    override func didMoveToView(view: SKView) {
        addBG()
        addPig()        
    }

    func addBG() {
        let bg = SKSpriteNode(imageNamed: "bg");
        addChild(bg)
    }

    func addPig() {
        let Pig = SKSpriteNode(imageNamed: "pig")
        porker = Porker(guy:Pig)
        addChild(Pig)
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
       /* Called when a touch begins */

         func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
            touch = touches.first!
        }
    }
}

Answers


Try this:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches{
// code goes here
 }
}

Remove the double up of touchesBegan.

import SpriteKit
import UIKit

class GameScene: SKScene {
    var porker:Porker!
    var touchLocation = CGFloat()

    override func didMoveToView(view: SKView) {
        addBG()
        addPig()        
    }

    func addBG() {
        let bg = SKSpriteNode(imageNamed: "bg");
        addChild(bg)
    }

    func addPig() {
        let Pig = SKSpriteNode(imageNamed: "pig")
        porker = Porker(guy:Pig)
        addChild(Pig)
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        let touch = touches.first!
        // do something with your touch
    }
}

Need Your Help

Can we swap the endianness of a data buffer, which is a fixed sized array, before mapping it to its eventual data structure?

c arrays endianness

Scenario: A remote machine (big endian) sends a message to a local machine (little endian) over RS422.

Any good suggestion to animations with SWT/JFace

java flash swt jface

I'm developing a desktop application using java + SWT/JFace, which I'm not very familiar. The program need to show some pictures presenting the program's progress like this.