SKAction更改SKShapeNode的颜色

时间:2014-04-01 19:18:59

标签: ios xcode sprite-kit skaction skshapenode

我正在使用SKAction中的repeatActionForever方法来更改SKShapeNode的颜色。 这是我的代码:

SKShapeNode *ship = [SKShapeNode node];
[ship setPath:CGPathCreateWithRoundedRect(CGRectMake(-15, -15, 40, 17), 6.25, 6.25, nil)];
ship.fillColor = [SKColor redColor];
ship.glowWidth = 3;

[ship runAction:[SKAction repeatActionForever:[SKAction sequence:@[
[SKAction colorizeWithColor:[SKColor blueColor] colorBlendFactor:1.0 duration:0.5],
[SKAction waitForDuration:0.3],[SKAction colorizeWithColorBlendFactor:1.0 duration:0.5],
[SKAction colorizeWithColor:[SKColor redColor] colorBlendFactor:1.0 duration:0.5],
[SKAction waitForDuration:0.3],
[SKAction colorizeWithColorBlendFactor:1.0 duration:0.5],
[SKAction waitForDuration:0.3]]]]];
return ship; //because it's a method

它看起来对我来说,但船没有改变颜色。我做错了什么,谢谢。

1 个答案:

答案 0 :(得分:4)

SKSpriteNode相比,SKShapeNode没有color属性。因此,colorizeWithColor:行动无法发挥作用。

请看一下这篇关于如何为fillColorstrokeColor设置动画的帖子:SKShapeNode - Animate color change