问题
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