0

Below is the code I'm having trouble with :

SKShapeNode* backgroundRect = [SKShapeNode shapeNodeWithRect:self.frame];
backgroundRect.fillColor = [UIColor whiteColor];

SKAction* colorBackground = [SKAction customActionWithDuration:0.5f actionBlock:^(SKNode *node, CGFloat elapsedTime)
{
    backgroundRect.fillColor = [UIColor colorWithRed:1.0f green:0.35f blue:0.35f alpha:1.0f];
    NSLog(@"akghajksgaks");
}];
[backgroundRect runAction:colorBackground];
NSLog(@"what");
backgroundRect.lineWidth = 0.0f;

I'm trying to animate changing the fill color of backgroundRect, but the actionBlock of SKAction never seems to be called. The only output I get is "What", so I don't understand how the first NSLog isn't being called. Any help would be greatly appreciated.

Marcus Buffett
  • 1,289
  • 1
  • 14
  • 32
  • do you addChild the backgroundRect? – CodeSmile Jun 09 '14 at 05:41
  • Yeah I do [self addChild:backgroundRect] right after this code – Marcus Buffett Jun 09 '14 at 13:28
  • 1) shapeNodeWithRect is not a class method of SKShapeNode, 2) When I implement your code (with changes to address 1), SKAction was called and the node changed to reddish. I suspect you want the color change to be gradual, but your custom SKAction won't do that. It will change the color of the node immediately and repeatedly to the same color (frame rate x 0.5F times). – 0x141E Jul 24 '14 at 16:59

0 Answers0