SKTransition之后没有出现所有级别

时间:2014-11-25 01:35:45

标签: ios swift sprite-kit sktransition

我正在尝试在游戏菜单和第一级之间进行转换。 但不是所有Level1(它是使用 Level1.sks文件(这里我设计了一个级别) Level1.swift(这里我创建了我的"英雄&#)构建的34; 等))屏幕上只显示英雄,但没有在Level1.sks中设计的位置。

我如何解决这个问题?

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 个答案:

答案 0 :(得分:1)

您需要将sks文件解压缩到SKScene对象中,以便可以将文件中的元素加载到场景中。

XCode通常在SKScene的.swift文件中生成一个名为unarchiveFromFile的方法。

以下代码应该有效:

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