Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Touch开始说,Touch从未被使用过_Ios_Swift_Sprite Kit_Uikit - Fatal编程技术网

Ios Touch开始说,Touch从未被使用过

Ios Touch开始说,Touch从未被使用过,ios,swift,sprite-kit,uikit,Ios,Swift,Sprite Kit,Uikit,我有下面的代码,我试图让我的屏幕上的猪移动,所以我添加了触摸开始功能 当我在函数中添加时,它说从未使用过touch,我应该用\uuu替换它。我做错了什么 import SpriteKit import UIKit class GameScene: SKScene { var porker:Porker! var touchLocation = CGFloat() override func didMoveToView(view: SKView) { a

我有下面的代码,我试图让我的屏幕上的猪移动,所以我添加了触摸开始功能

当我在函数中添加时,它说从未使用过touch,我应该用
\uuu
替换它。我做错了什么

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!
        }
    }
}
导入SpriteKit
导入UIKit
类游戏场景:SKScene{
小猪:小猪!
var touchLocation=CGFloat()
覆盖func didMoveToView(视图:SKView){
addBG()
addPig()
}
func addBG(){
设bg=SKSpriteNode(图像名为:“bg”);
addChild(bg)
}
func addPig(){
let Pig=SKSpriteNode(图像名为“Pig”)
猪=猪(家伙:猪)
addChild(猪)
}
覆盖功能触摸开始(触摸:设置,withEvent事件:UIEvent?){
/*当触摸开始时调用*/
func TouchesBegined(触摸:设置,withEvent事件:UIEvent?){
首先!
}
}
}

移除双重触摸开始

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
    }
}
导入SpriteKit
导入UIKit
类游戏场景:SKScene{
小猪:小猪!
var touchLocation=CGFloat()
覆盖func didMoveToView(视图:SKView){
addBG()
addPig()
}
func addBG(){
设bg=SKSpriteNode(图像名为:“bg”);
addChild(bg)
}
func addPig(){
let Pig=SKSpriteNode(图像名为“Pig”)
猪=猪(家伙:猪)
addChild(猪)
}
覆盖功能触摸开始(触摸:设置,withEvent事件:UIEvent?){
让我们先接触!
//用你的触觉做点什么
}
}

移除双重触摸开始

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
    }
}
导入SpriteKit
导入UIKit
类游戏场景:SKScene{
小猪:小猪!
var touchLocation=CGFloat()
覆盖func didMoveToView(视图:SKView){
addBG()
addPig()
}
func addBG(){
设bg=SKSpriteNode(图像名为:“bg”);
addChild(bg)
}
func addPig(){
let Pig=SKSpriteNode(图像名为“Pig”)
猪=猪(家伙:猪)
addChild(猪)
}
覆盖功能触摸开始(触摸:设置,withEvent事件:UIEvent?){
让我们先接触!
//用你的触觉做点什么
}
}
试试这个:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches{
// code goes here
 }
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
接触{
//代码在这里
}
}
试试这个:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches{
// code goes here
 }
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
接触{
//代码在这里
}
}

您已将一个函数放入函数中。。。。删除内部函数…您已将函数放入函数中。。。。删除内部函数…当您添加“touch=touch.first”时,它表示我正在使用一个未解析的标识符。当您添加“touch=touch.first”时,它表示我正在使用一个未解析的标识符。您可以添加一些代码的详细信息吗?如何解决问题中的问题?谢谢你能为你的代码添加一些细节吗?如何解决问题?谢谢