SKAction change the color of a SKShapeNode
Asked Answered
B

1

7

I am using the repeatActionForever method from SKAction to change the color of an SKShapeNode. Here's my code:

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

It looks right to me but the ship doesn't change color. What am I doing wrong, thanks.

Bevbevan answered 1/4, 2014 at 19:18 Comment(0)
F
6

In contrast to a SKSpriteNode, a SKShapeNode does not have a color property. So your colorizeWithColor: action won't work.

Take a look at this post on how to animate the fillColor and strokeColor: SKShapeNode - Animate color change

Flay answered 1/4, 2014 at 20:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.