Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

ios - Not appearing all level after SKTransition

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

        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...