Not appearing all level after SKTransition

163 views Asked by At

I am trying to do a transition between game menu and the first level. But instead of all Level1 (it is built by using an Level1.sks file(here I have designed a level) and Level1.swift(here I have created my "hero" etc.)) on the screen appears just hero, but no locations that was designed in Level1.sks.

How I can resolve this problem?

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        if (playbutton .containsPoint(location)){

            runAction(SKAction.playSoundFileNamed("play.wav", waitForCompletion: false))


            let transition = SKTransition.revealWithDirection(SKTransitionDirection.Down, duration: 1)
            let scene = Level1(size: CGSizeMake(1024, 768))
            scene.scaleMode = SKSceneScaleMode.AspectFill
            self.scene?.view?.presentScene(scene, transition: transition)
            transition.pausesOutgoingScene = true

        }
1

There are 1 answers

0
ZeMoon On

You need to unarchive the sks file into an SKScene object so that the elements from the file can be loaded into the scene.

XCode usually generates a method called unarchiveFromFile in the SKScene's .swift file.

The following code should work:

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        if (playbutton .containsPoint(location)){

            runAction(SKAction.playSoundFileNamed("play.wav", waitForCompletion: false))

            if let scene = Level1.unarchiveFromFile("GameScene") as? GameScene {

                let transition = SKTransition.revealWithDirection(SKTransitionDirection.Down, duration: 1)
                scene.scaleMode = SKSceneScaleMode.AspectFill
                self.scene?.view?.presentScene(scene, transition: transition)
                transition.pausesOutgoingScene = true
            }
        }
    }
}