【问题标题】:Using pan gesture recognizer in SpriteKit在 SpriteKit 中使用平移手势识别器
【发布时间】:2015-02-24 16:22:31
【问题描述】:

我正在使用 SpriteKit 开发一款游戏,我想移动一些精灵,但我一次只需要移动一个精灵。如何在 SpriteKit 中使用平移手势识别器?我尝试了正常的方式,但我得到了一些错误,所以我想也许它有一个特殊的方式。

【问题讨论】:

  • 请告诉我们您已经尝试过什么。你遇到了什么错误?

标签: ios swift sprite-kit uigesturerecognizer uipangesturerecognizer


【解决方案1】:

要在游戏中添加平移手势识别器,请在 GameScene 的 didMove 方法中添加手势识别器。然后在您的 GameScene 文件中添加一个新函数(handlePanFrom,如下所示),当手势被识别时将调用该函数。

override func didMove(to view: SKView) {
    // Create the gesture recognizer for panning
    let panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePanFrom))
    // Add the gesture recognizer to the scene's view
    self.view!.addGestureRecognizer(panGestureRecognizer)
}

@objc func handlePanFrom(_ recognizer: UIPanGestureRecognizer) {
    // This function is called when a pan gesture is recognized. Respond with code here.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多