所以我正在制作游戏,之前使用左右按钮移动。我正在考虑将其更改为类似于此http://gyazo.com/05b6079862874a282ad14220e7267bd1的自定义类型的滑块我不知道如何让它更新触摸开始,所以请注册滑动手指。到目前为止我所拥有的是:
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.sliderBox{
let move = touch.locationInNode(self)
slider.position.x = move.x
}
}
这会让红点移动到我触摸的位置,但是我需要能够像这样,并且能够在按住它时滑动。感谢您抽出宝贵时间来研究这个问题。
答案 0 :(得分:0)
通过更改覆盖func touchesBegan到func touchesMoved
来修复override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if self.nodeAtPoint(location) == self.slider{
let move = touch.locationInNode(self)
slider.position.x = move.x
}
}
}