I have 3 SKScenes in SpriteKit, Swift:
Level 1
Game Over
- Level 2.
In Level 1 and Level 2, my character movement is done by the following code:
class Level1: SKScene, SKPhysicsContactDelegate {
func swipedRight(sender:UISwipeGestureRecognizer){
let moveRIGHT = SKAction.moveBy(CGVectorMake(60, 0), duration: 1)
Character.runAction(moveRIGHT)
}
func swipedLeft(sender:UISwipeGestureRecognizer){
let moveLEFT = SKAction.moveBy(CGVectorMake(-60, 0), duration: 1)
Character.runAction(moveLEFT)
}
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)
And when the character dies in Level 1, I transition to the "Game Over" SKScene where you can retry Level 1 if you'd like.
However after going back and forth between Level 1 - Game Over - Level 1 - Game Over - Level 1 - Game Over etc, the FPS dramatically drops whenever you do a UISwipeGesture on Level 1 AND Level 2.
I then decided to remove the UISwipeGestureRecognizer from Level 1, and then purposely go back and forth between Level 1 and Game Over, and then go to Level 2. There was no FPS drop when using UISwipeGestures in Level 2 after doing this.
Therefore, my conclusion is that whenever I load a SKScene with the UISwipeGestureRecognizer over and over again, it creates this FPS drop whenever you try and initiate a swipe.
So: 1) Am I implementing this UISwipeGestureRecognizer wrongly?
2) Is there another way I can get the same effect of character movement without using UISwipeGestureRecognizer?
Thanks heaps guys!