SKAction更改SKShapeNode的颜色

rae*_*010 6 xcode ios 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
Run Code Online (Sandbox Code Playgroud)

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

小智 6

与 a 相比SKSpriteNode, aSKShapeNode没有color属性。所以你的colorizeWithColor:行动是行不通的。

看看这篇关于如何为fillColorand设置动画的帖子strokeColorSKShapeNode - Animate color change