1
scenekit人物移動我剛剛完成我的scenekit遊戲,在其中我有一個移動的特性而開始與單個磁帶移動gesture.I希望當按下的按鈕移動到,所以我創建播放/暫停按鈕在skscene class.How我讓我的角色只有當我按下播放按鈕時纔會移動? 由於這種圖像 這裏是我的代碼如何控制與SkSpriteNode
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self)
let _node:SKNode = self.atPoint(location)
if(_node.name == "Play Button"){
parentView?.startGame()
}
if self.pauseNode.contains(location) {
if !self.isPaused {
self.pauseNode.texture = SKTexture(imageNamed: "Pause Button")
}
else {
self.pauseNode.texture = SKTexture(imageNamed: "Play Button")
}
self.isPaused = !self.isPaused
}
}
功能在LevelOneViewController viewDidLoad中()
func move(){
Character.idle()
let startTap = UITapGestureRecognizer(target: self, action: #selector(LevelOneViewController.handleStartTap(_:)))
scnView.addGestureRecognizer(startTap)
let stopTap = UITapGestureRecognizer(target: self, action: #selector(LevelOneViewController.handleStopTap(_:)))
scnView.addGestureRecognizer(stopTap)
stopTap.numberOfTapsRequired = 2
}
move()
}