Search code examples
objective-cios7sprite-kitobjective-c-2.0

How to repeat this action 3 times instead of repeating it forever- Sprite Kit


How to repeat this action 3 or 2 times instead of repeating it forever

 SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:@"AmericanTypewriter-Bold"];
 label.text = @"Boom";
 label.fontColor = [SKColor blackColor];
 label.fontSize = 90;
 label.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)+25);

 SKAction *disappear = [SKAction fadeAlphaTo:0.0 duration:0.2];
 SKAction *appear = [SKAction fadeAlphaTo:1.0 duration:0.2];
 SKAction *pulse = [SKAction sequence:@[disappear,appear]];

 [label runAction:[SKAction repeatActionForever:pulse]];

 [self addChild:label];

Solution

  • You need to use SKAction's repeatAction:count: method documented here.

    [label runAction:[SKAction repeatAction:pulse count:3]];