我在我的遊戲中遇到了UIGestures問題 在遊戲場景中,它們完美無缺,但是當我移動到另一個場景時,如果我使用它們(刷卡)而不是崩潰。在離開場景時刪除UIGestures
我知道我必須在Gamescene文件中使用willmovefromview方法,但在這已經工作2天,仍然沒有工作..
這裏是我的視圖 - 控制文件(見註釋的手勢功能和手勢識別)
import UIKit
import SpriteKit
import AVFoundation
class GameViewController: UIViewController, UITextFieldDelegate{
//gesture functions
func swipedRight(sender: UISwipeGestureRecognizer){
let skView = view as SKView
let gameScene = skView.scene as GameScene
gameScene.swipedRight1(sender)
}
func swipedLeft(sender: UISwipeGestureRecognizer){
let skView = view as SKView
let gameScene = skView.scene as GameScene
gameScene.swipedLeft1(sender)
}
func swipedDown(sender: UISwipeGestureRecognizer){
let skView = view as SKView
let gameScene = skView.scene as GameScene
gameScene.swipedDown1(sender)
}
func swipedUp(sender: UISwipeGestureRecognizer){
let skView = view as SKView
let gameScene = skView.scene as GameScene
gameScene.swipedUp1(sender)
}
override func viewDidLoad() {
super.viewDidLoad()
let skView = view as SKView
skView.multipleTouchEnabled = false
scene = GameMenuScene(size: skView.bounds.size)
//scene.scaleMode = SKSceneScaleMode.ResizeFill
skView.showsFPS = true
skView.showsNodeCount = true
skView.presentScene(scene)
//Gesture recognizers
let swipeRight:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))
swipeRight.direction = .Right
view.addGestureRecognizer(swipeRight)
let swipeLeft:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedLeft:"))
swipeLeft.direction = .Left
view.addGestureRecognizer(swipeLeft)
let swipeUp:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedUp:"))
swipeUp.direction = .Up
view.addGestureRecognizer(swipeUp)
let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .Down
view.addGestureRecognizer(swipeDown)
}
override func viewDidLayoutSubviews() {
}
override func prefersStatusBarHidden() -> Bool {
return true
}
}
PS:我的應用程序開始在menuscene,並揮筆只能是活躍在gamescene,所以我覺得我必須使用didmovetoview方法爲好。
,這裏是我的gamescene文件didmovetoview方法和willmovefromview方法:
override func didMoveToView(view: SKView) {
}
override func willMoveFromView(view: SKView) {
}
誰來幫幫我? 在此先感謝
錯誤:SKView?沒有名爲'gestureRecognizers'的成員 – DNC 2014-12-05 00:41:10
使用您添加了手勢識別器的相同視圖。 – Mundi 2014-12-05 00:52:15
你是什麼意思?我在我的視圖控制器中添加了手勢識別器,您可以在我的帖子中看到代碼。 – DNC 2014-12-05 01:00:21