-1

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
  • 1
    You need to unarchive the SKS file using NSKeyedUnarchiver first
    – ZeMoon
    Nov 25, 2014 at 6:40

1 Answer 1

1

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
            }
        }
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.