【发布时间】:2019-04-18 20:40:21
【问题描述】:
我正在制作一个游戏,我在屏幕上移动一个精灵,但如果我点击屏幕,它会移动到那个位置,我只希望它在我将手指放在屏幕上时移动,这样精灵就会跟随我的手指,它不会通过我的物体传送
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchLocation = touch.location(in: self)
player.position.x = touchLocation.x
}
}
我试过这个(玩家是我的精灵)并且它有效,当我移动我的手指时,精灵会跟随,但是如果我点击屏幕一侧的 fx,它会传送到那个位置而我没有希望发生这种情况。
【问题讨论】:
-
你想让它动画到新的位置吗?或者根本没有移动,因为它最初没有被按下来拖动?
-
如果我只是在屏幕上按下它不应该移动到那个位置,但是如果我在屏幕上拖动我的手指它应该跟随,但我不知道该怎么做。跨度>
标签: swift xcode skspritenode touchesmoved