我正在使用 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/