-1

我正在尝试在游戏菜单和第一级之间进行转换。但不是所有的Level1(它是通过使用Level1.sks文件(这里我设计了一个关卡)Level1.swift(这里我已经创建了我的“英雄”等))在屏幕上出现的只是英雄,但没有在 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

        }
4

1 回答 1

1

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

XCode 通常会生成一个unarchiveFromFile在 SKScene 的 .swift 文件中调用的方法。

以下代码应该可以工作:

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
            }
        }
    }
}
于 2014-11-25T11:57:13.647 回答