Make SKSpriteNode flash white with SKAction colorizeWithColor

百般思念 提交于 2020-02-03 08:14:08

问题


Ok so I have a sprite thats suppose to flash white when hit by something, I'm using this

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

What happens is the sprite flashes, but instead of white, it just turns transparent. If I use any other color like redColor, blueColor, ect.. It works perfect.

How can I get it to actually turn white?

Thanx for the help!!! :D


回答1:


Colorize with white should give you the image's original colors. It effectively means "no colorizing". You can't colorize it "white". Instead use a texture you prepared that makes the image look brighter.




回答2:


Try this:

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)
}



回答3:


Thank you so much for coming up with the alpha trick. Perfect for what I was looking for.

You may use

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


来源:https://stackoverflow.com/questions/22029302/make-skspritenode-flash-white-with-skaction-colorizewithcolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!