ios - 在 SpriteKit 中使用平移手势识别器

标签 ios swift sprite-kit uigesturerecognizer uipangesturerecognizer

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

最佳答案

要在游戏中添加平移手势识别器,请在 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.
}

关于ios - 在 SpriteKit 中使用平移手势识别器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28700961/

相关文章:

php - 用htaccess密码保护识别 "apple-touch-icon"

ios - 将代码更新为最新的 Swift 4 语法会导致 "Thread 1: Fatal error: Index out of range"错误

ios - 无法让 google 登录来处理 URL

ios7 - Cocos2D 调度更新 SpriteKit 上的 CCNode

swift - 使 SKSpriteNode 运行 Action 与屏幕边缘碰撞

php - 表情符号到 JSON 编码,发布到网络服务器

iphone - 为什么 Xcode 在 iOS 模拟器和设备上运行我的项目的旧版本?

iphone - 可达性 block 应用

ios - UIImage animationImages 色调颜色?

reference - iOS7创建和使用SKTextureAtlas的正确方法是什么?