LoginSignup
2
2

More than 5 years have passed since last update.

SpriteKit入門 -17-

Posted at

SKActionに名前をつけて実行中のアクションを削除してみます。
下記のようにすると、1回目にタップすると点滅を始め、2回目にタップすると点滅が中断するようになります。

HelloScene.m
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    SKSpriteNode *spaceship = (SKSpriteNode *)[self childNodeWithName:@"spaceship"];
    if (spaceship != nil) {
        SKAction *action = [spaceship actionForKey:@"pulse"];
        if (action != nil) {
            [spaceship removeActionForKey:@"pulse"];
        }
        else {
            SKAction *fadeOut = [SKAction fadeOutWithDuration:1.0];
            SKAction *fadeIn = [SKAction fadeInWithDuration:1.0];
            SKAction *pulse = [SKAction sequence:@[fadeOut, fadeIn]];
            SKAction *pulseForever = [SKAction repeatActionForever:pulse];
            [spaceship runAction:pulseForever withKey:@"pulse"];
        }
    }
}

今回はここまで。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2