SpriteKit场景转换XCode 7

时间:2016-01-09 07:16:39

标签: ios swift sprite-kit

我的代码在这里出了什么问题?我正试图从GameScene过渡到ActionScene。在模拟器中,对精灵的触摸没有响应。请帮助!!

import SpriteKit

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        /* Setup your scene here */
        let sprite = SKSpriteNode(imageNamed:"Spaceship")

        sprite.xScale = 0.5
        sprite.yScale = 0.5
        sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))


        self.addChild(sprite)
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        /* Called when a touch begins */

        for touch in touches {
            let location = touch.locationInNode(self)
            let touchedNode = nodeAtPoint(location)

            if touchedNode.name == "sprite" {
                let transition = SKTransition.revealWithDirection(.Down, duration: 0.5)

                let ActionScene = GameScene(size:scene!.size)

                ActionScene.scaleMode = .AspectFill

                scene?.view?.presentScene(ActionScene, transition: transition)
            }


        }
    }

    override func update(currentTime: CFTimeInterval) {
    /* Called before each frame is rendered */
    }
}

1 个答案:

答案 0 :(得分:1)

您初步确定了ActionScene错误。如果你想转换到ActionScene,你就无法初始化GameScene(因为我假设你已经在GameScene上,并且正在尝试过渡到actionScene)。所以改变这段代码

let actionScene = GameScene(size:scene!.size)

到这个

let actionScene = ActionScene(size:scene!.size)