我有下面的代码,我正在努力使我的屏幕上的猪移动,所以我添加了一个触摸开始功能。
当我在函数中添加时,它说touch从未使用过,我应该用_替换它。我做错什么了?

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!
        }
    }
}

最佳答案

试试这个:

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

关于ios - 触控开始功能,说从未使用过触控,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35024221/

10-09 02:22