0

So I'm currently creating a game. I have a number of Scenes: Menu, settings, gameScene and GameOverScene.

Transition between ALMOST ALL scenes is without a problem, the code I'm using to transition is: (e.g. for menu to GameScene)

let secondScene = GameScene(size: self.size)
let transition = SKTransition.pushWithDirection(.Up, duration: 0.7)
secondScene.scaleMode = SKSceneScaleMode.AspectFill
self.scene!.view?.presentScene(secondScene, transition: transition)

However, my GameScene to GameOverScene is extremely glitchy. There is usually a lengthy pause.

The entire contents of GameOverScene is:

import Foundation
import SpriteKit

class GameOverScene: SKScene {


    override func didMoveToView(view: SKView) {
        let myLabel = SKLabelNode(fontNamed:"American Typrewriter")
        myLabel.text = "Game Over!";
        myLabel.fontSize = 45;
        myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));

        self.addChild(myLabel)
   }
}

Therefore I believe it's unlikely that this is the cause of the delay in transition.

The code I'm using to invoke a 'game over' is:

override func update(currentTime: CFTimeInterval) {

if sprite.position.y < 100 {gameOver()}
}

func gameOver() {

    // Loads GameOver Scene //
    let secondScene = GameOverScene(size: self.size)


    // Creates vibration //
    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))


        func boatSink() {
        sprite.physicsBody = nil
        sprite.physicsBody?.affectedByGravity = false
        sprite.physicsBody?.dynamic = false

        let spritefly = SKAction.moveTo(CGPointMake(400,20), duration:2.0)
        car.runAction(spritefly) }



    let transition = SKTransition.pushWithDirection(.Up, duration: 3.0) 
    let nextScene = GameOverScene(size: scene!.size)
    nextScene.scaleMode = .AspectFill

    scene?.view?.presentScene(nextScene, transition: transition)        
}

I've experimented with the use of Delays, such as using:

let skView = self.view! as SKView
            let scene = GameOverScene(size: self.scene!.size)
            scene.size = skView.bounds.size
            scene.scaleMode = .AspectFill

  let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 1 * Int64(NSEC_PER_SEC))
        dispatch_after(time, dispatch_get_main_queue()) {



            let sceneTransition = SKTransition.doorsCloseHorizontalWithDuration(2.0)
            sceneTransition.pausesOutgoingScene = true;
            skView.presentScene(scene, transition: sceneTransition)}

To give time to load but this does not work.

I've also tried using 'pausesOutgoingScene' and pausesIncomingScene' to no avail.

I finally tried slowing the current scene to 0.0 using:

func pauseGameScene() {
        self.physicsWorld.speed = 0.0
        self.speed = 0.0
    }

though this just stopped the code from progressing any further.

My questions are: 1. Is there anything really obvious I'm not thinking about with my transitions? 2. Is there a way to load all Scenes in advance, I'm sure that this probably will only provide minor improvement but it is definitely an area I've not yet looked at.

  • 1
    Remove everything from didMoveToView of a GameoverScene and see if delay occurs... – Whirlwind Nov 11 '15 at 12:47
  • Just tried this - no delay at all. Do you have any recommendations as to how I go about organising the coding in the GameOverScene so I can minimise nodes/ stuff in didMoveToView? – Daniel Richardson Nov 11 '15 at 16:07
  • It's probably SKLabelNode related "issue"...You have to provide the right font name. Take a look at my answer here: http://stackoverflow.com/q/33330247/3402095 – Whirlwind Nov 11 '15 at 16:09
  • I've had a look on iosfont.com and that doesn't look to be the issue but moving things out of didMoveToView has massively helped! Thanks – Daniel Richardson Nov 11 '15 at 16:25
  • "American Typewriter" is a font family ... You have to load specific font "AmericanTypewriter" (no space between words). It should work without delay from didMoveToView. – Whirlwind Nov 11 '15 at 16:29
  • Also I just noticed that you have a typo in your code... "American TypRewriter" that "r" is surplus, so what's happening currently is that iOS search for a wrong, non-existing font and probably go through all possible fonts - thus a delay. – Whirlwind Nov 11 '15 at 16:49
  • Ah, sorry yeah that's a typo across transcription as I've just checked the app and I've not got the typos in there but good spot! :) – Daniel Richardson Nov 11 '15 at 17:16
  • 1
    Weird because this is a know issues with SKLabelNode when wrong font name is used : http://stackoverflow.com/a/23624123/3402095. Also If I use your code I can re-create the issue (I got delay), but if I use correct font name (remove a typo) it loads instantly even if I load entire font family (which is probably a bit slower, but still not noticeable slower) ... – Whirlwind Nov 11 '15 at 17:56
  • I've found out what it is! Not connected to the font but instead I have a loop running elsewhere in my game scene and the game continues to run it. It seems to be working fine now so it was likely to be either this or me correcting the mistype inadvertently! – Daniel Richardson Nov 11 '15 at 20:34

0 Answers0