使用SKAction colorizeWithColor使SKSpriteNode闪烁白色

时间:2014-02-26 00:37:24

标签: objective-c sprite-kit skspritenode

好的,所以我有一个精灵,假设在遇到某些东西时会闪现白色,我正在使用这个

SKAction *changeColorAction = 
[SKAction colorizeWithColor:[SKColor whiteColor] colorBlendFactor:1.0 duration:1];

精灵会闪烁,但不是白色,而是变成透明。 如果我使用任何其他颜色,如redColor,blueColor等,它的工作完美。

如何让它真正变白?

Thanx的帮助! :D

3 个答案:

答案 0 :(得分:1)

使用白色着色应该可以为您提供图像的原始颜色。它实际上意味着“没有着色”。你不能把它着色为“白色”。而是使用您准备的纹理使图像看起来更亮。

答案 1 :(得分:0)

试试这个:

func blink() {

    inviolable = true
    lifeCount--

    if lifeCount <= 0 {

        lifeCount = 0
    }

    var changeColorAction: SKAction = SKAction.runBlock { () -> Void in

        self.alpha = 0.5
    }

    var changeBackAction: SKAction = SKAction.runBlock { () -> Void in

        self.alpha = 1.0
    }

    var waitAction: SKAction = SKAction.waitForDuration(0.2)

    var finalAction: SKAction = SKAction.runBlock { () -> Void in

        self.inviolable = false
    }

    var combined: SKAction = SKAction.sequence(
        [   changeColorAction,
            waitAction,
            changeBackAction,
            waitAction,
            changeColorAction,
            waitAction,
            changeBackAction,
            waitAction,
            changeColorAction,
            waitAction,
            changeBackAction,
            changeColorAction,
            waitAction,
            changeBackAction,
            changeColorAction,
            waitAction,
            changeBackAction,
            finalAction])

    runAction(combined)
}

答案 2 :(得分:0)

非常感谢您提出alpha技巧。非常适合我想要的东西。

您可以使用

run(SKAction.repeat(SKAction.sequence(changeColorAction,
            waitAction,
            changeBackAction,
            waitAction), count: 4)