0
votes

I'm sure this is fairly simple, but I've been struggling with the best way to implement this effect in SpriteKit. I have a laser node which I want to turn off and on every x # of seconds. I've tried setting up SKActions to turn off sound and fade image out, but I'm not sure how to have the node be aware of weather it is current off or on in the SKAction. I guess what I am looking for is some type of callback when each SKAction in my runAction completes. That way I could set a flag to say of the laser is on or off and use that when a collision occurs so I know how to handle it. I'm not sure if this is best way to go about this either. Thanks for your help.

1

1 Answers

0
votes

For anyone interested what I was missing were runBlocks. ruNBlacks are SKActions that fire off a piece of code. I added run blocks before the laser turns on and before it turns off so it can update its status. Looks like this will work great!

    SKAction *soundAction = [SKAction playSoundFileNamed:@"Laser.m4a" waitForCompletion:NO];
    SKAction *fadeInAction = [SKAction fadeInWithDuration: .5];
    SKAction *firstWaitAction = [SKAction waitForDuration:1.5];
    SKAction *fadeOutAction = [SKAction fadeOutWithDuration: .5];
    SKAction *secondWait1Action = [SKAction waitForDuration:2];

    SKAction *laserAnimAction = [SKAction sequence:@[
        [SKAction runBlock:^
        {
            self.isOn=YES;
        }],
        soundAction,
        fadeInAction,
        firstWaitAction,
        [SKAction runBlock:^
        {
            self.isOn=NO;
        }], fadeOutAction,
        secondWaitAction
        ]];