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"];
}
}
}
今回はここまで。