【问题标题】:How to gradually (animated) change background color in Spritekit?如何在 Spritekit 中逐渐(动画)改变背景颜色?
【发布时间】:2017-01-09 14:24:05
【问题描述】:

我尝试过的解决方案:

Gradually change background color in Swift

Swift : Background Color fading animation (SpriteKit)


我目前拥有的(不工作):

class GameScene: SKScene, SKPhysicsContactDelegate{

    var background = SKSpriteNode()

    var colorizeToRed = SKAction()


    override func didMoveToView(view: SKView) {

        background = SKSpriteNode(color: UIColor.blueColor(), size: self.frame.size)

        background.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2)

        background.zPosition = 15

        colorizeToRed = SKAction.colorizeWithColor(SKColor(red: 90, green: 0, blue: 0, alpha: 1), colorBlendFactor: 1.0, duration: 2.0)

        background.runAction(colorizeToRed)

    }

}

我的问题:

我没有看到背景改变颜色。我唯一看到它改变颜色的情况是,如果我使用 self.backgroundColor = UIColor().aColor 直接设置它而不使用动画。

编辑:事实上,我什至看不到蓝色背景...我的 SKSpriteNode 出了点问题,但是什么?


问题:

如何在 Spritekit 中逐渐(动画)改变背景颜色?


问之前:

1) 是的,我已经尝试更改 zPosition 以防 SKNode 被隐藏。

2) 是的,我已经检查了SKAction.colorizeWithColor() 的文档。

3) 是的,我几乎可以肯定我的问题的解决方案非常简单(可能是我的一些错误),但是呢?

4) 是的,我愿意接受任何告诉我错误在我的代码中的其他地方的建议,但前提是您要准确说明错误可能在哪里。

5) 不,我不会在这里发布我的整个代码,如有需要,请询问具体部分。


提前感谢您提供的任何帮助^^!

【问题讨论】:

    标签: ios swift animation sprite-kit background-color


    【解决方案1】:

    从外观上看,我认为您只是忘记将背景添加到场景中。试试这个:

    addChild(background)
    

    如果这没有帮助,请继续阅读...

    如果您只是淡入 SKSpriteNode,那么您可以使用 SKAction.fadeIn 淡入节点。只需将其 alpha 设置为 0 即可启动并通过执行以下操作淡入:

    background.run(SKAction.fadeInWithDuration(2))
    

    【讨论】:

    • 我忘记了 addChild...谢谢 ^^。我现在要睡觉了-___-
    • @Coder1000 嗨,伙计,发生在所有人身上,重要的是要解决。下次尝试用断点和PO调试它来控制台调试,它救了我很多次。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    • 2012-06-13
    • 2012-03-11
    • 2010-12-17
    相关资源
    最近更新 更多