0
我想輕掃手勢添加到從主場景繼承場景(GameScene)respondToSwipeGesture在很多場景
extension GameScene {
class Scene1: GameScene {
override func didMove(to view: SKView) {
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeRight.direction = .right
view.addGestureRecognizer(swipeRight)
let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
view.addGestureRecognizer(swipeDown)
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeUp.direction = UISwipeGestureRecognizerDirection.up
view.addGestureRecognizer(swipeUp)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
view.addGestureRecognizer(swipeLeft)
}
}
class Scene2: GameScene {
override func didMove(to view: SKView) {
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeRight.direction = .right
view.addGestureRecognizer(swipeRight)
let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
view.addGestureRecognizer(swipeDown)
let swipeUp = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeUp.direction = UISwipeGestureRecognizerDirection.up
view.addGestureRecognizer(swipeUp)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
view.addGestureRecognizer(swipeLeft)
}
}
}
而且每次我必須不時在所有重新編寫代碼等及其他場景。也許,還有另一種出路。
我試過但我做不到。 – Proffan
是什麼?這是沒有意義的 – Knight0fDragon
var scene = GameScene(size:CGSize(width:1024,height:768)) func viewDidLoad(){ super.viewDidLoad() let view = self.view as! SKView let swipeDown = UISwipeGestureRecognizer(target:scene,action:#selector(scene.respondToSwipeGesture(gesture :) :)) swipeDown.direction = .down view.addGestureRecognizer(swipeRight) – Proffan