【发布时间】:2017-04-27 19:01:26
【问题描述】:
我刚刚完成了我的场景包游戏,其中我有一个移动角色,它以单个磁带手势开始移动。我希望它在按下按钮时移动,所以我在 skscene 类中创建播放/暂停按钮。我如何制作我的只有当我按下播放按钮时角色才会移动? 如此图 这是我的代码
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()
}
【问题讨论】: