swift - 返回 GameScene 后 SpriteNodes 搞砸了 (Swift)

标签 swift sprite nodes skscene

我有两个场景。游戏场景和游戏场景。 GameScene 更像是“主屏幕”,而 PlayScene 是实际游戏发生的地方。转换到 PlayScene 时一切正常。

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

    for touch: AnyObject in touches {
        let location = touch.locationInNode(self)

        if self.nodeAtPoint(location) == self.playbutton {

            let scaleDown = SKAction.scaleBy(0.01, duration: 1.0)

            self.playbutton.runAction(scaleDown)

            var scene = PlayScene(size: self.size)
            let skView = self.view as SKView!
            scene.size = skView.bounds.size

            let transition = SKTransition.pushWithDirection(SKTransitionDirection.Left, duration: 3)

            transition.pausesOutgoingScene = false
            skView.presentScene(scene, transition: transition)

        }
    }
}

但是...当有人在 PlayScene 中点击“重播”按钮后被送回 GameScene 时,GameScene 中的所有节点都会困惑。它们的尺寸被放大,甚至一个节点向后反转。

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

    let touch = touches.anyObject() as UITouch
    let touchLocation = touch.locationInNode(self)

        isFingerTouching = true


    if self.nodeAtPoint(touchLocation) == self.facebookButton {
        facebookButtonPushed()
    }

    if self.nodeAtPoint(touchLocation) == self.twitterButton {
        twitterButtonPushed()
    }

    if self.nodeAtPoint(touchLocation) == self.replay {

        var scene = GameScene(size: self.size)
        let skView = self.view as SKView!
        scene.size = skView.bounds.size

        let transition = SKTransition.crossFadeWithDuration(1.0)
        transition.pausesOutgoingScene = false
        skView.presentScene(scene, transition: transition)

    }

}

我不确定这是如何发生的,但任何形式的帮助都会很棒。谢谢!

最佳答案

我也遇到过同样的问题。您需要设置scaleMode (在此处查看有关“scaleMode”的更多信息)。只需将此代码放入 viewDidLoad() 即可:

self.scaleMode = .AspectFill

希望这有帮助。

关于swift - 返回 GameScene 后 SpriteNodes 搞砸了 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28759975/

相关文章:

java - 获取二叉树内部节点数 Java

c - 链表: how to make sorter checker in C?

ios - 为什么我的 UITableViewCell 中的多行 UILabel 在第一次加载时被截断,但在滚动时会自行更正?

jquery - 如何为所有 Sprite 图像制作动画?

ios - Swift,tableview 没有被填充

java - 从java获取不正确的子图像

css - 在网站中包含大量图标的最佳方法?

c++ - 链表的 Delete_At 函数使程序崩溃

swift - 如何获得二进制包的校验和?

ios - 如何防止CGContext中风路径或绘制路径线条画向上 float /旋转回来?