【发布时间】:2015-07-17 00:39:43
【问题描述】:
我有一个简单的问题。
我想向左或向右移动精灵,以防玩家触摸屏幕的左侧或右侧。它应该持续移动,直到玩家停止按屏幕。
请告诉我你会怎么做。
谢谢!
【问题讨论】:
-
Any 详细信息会有所帮助。您在游戏中使用什么样的引擎或框架?有代码示例吗?
我有一个简单的问题。
我想向左或向右移动精灵,以防玩家触摸屏幕的左侧或右侧。它应该持续移动,直到玩家停止按屏幕。
请告诉我你会怎么做。
谢谢!
【问题讨论】:
这里是你如何使用“UIGestureRecognizerDelegate”:
class TouchViewController: UIViewController, UIGestureRecognizerDelegate{...}
覆盖:
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
if let touch: UITouch = touches.first as? UITouch{
let touchLocation = touch.locationInView(self.view) as CGPoint
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
}
如果你能分享你的代码,你会更容易理解问题...
【讨论】: