【问题标题】:Moving a sprite with long taps长按移动精灵
【发布时间】:2015-07-17 00:39:43
【问题描述】:

我有一个简单的问题。

我想向左或向右移动精灵,以防玩家触摸屏幕的左侧或右侧。它应该持续移动,直到玩家停止按屏幕。

请告诉我你会怎么做。

谢谢!

【问题讨论】:

  • Any 详细信息会有所帮助。您在游戏中使用什么样的引擎或框架?有代码示例吗?

标签: ios swift nodes


【解决方案1】:

这里是你如何使用“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)
}

如果你能分享你的代码,你会更容易理解问题...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 2021-06-15
    • 2023-03-15
    • 2017-05-19
    • 2017-05-27
    • 1970-01-01
    相关资源
    最近更新 更多