iPhone_360 iPhone_360 - 1 year ago 96
Objective-C Question

CCBlinkTo in SpriteKit

How can I achieve CCBlink like action in Sprite-Kit ? I want 10 blink in 2.

id blink = [CCBlink actionWithDuration:2.0f blinks:10];
id calBck = [CCCallBlock actionWithBlock:^{
[enemy expired];
[HeroSprite runAction:[CCSequence actions:blink, calBck, nil]];

Answer Source

This example uses the alpha property to create the blink effect. You might as well use the hidden property and a runBlock action, as @LearnCocos2D suggested.

Blink time: 2.0 / 10 = 0.2, so 0.1 seconds for each fade-in and fade-out.

    HeroSprite.alpha = 0.0;

    SKAction *blinkSequence = [SKAction sequence:@[
        [SKAction fadeAlphaTo:1.0 duration:0.1],
        [SKAction fadeAlphaTo:0.0 duration:0.1]

    [HeroSprite runAction:[SKAction repeatAction:blinkSequence count:10] completion:^{
        [enemy expired];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download