I have the following code:
-(void)aggravatedSeek:(SKSpriteNode *)target{
_isAggravated = YES;
SKAction *action = [SKAction runBlock:^{
double randTime = 0.2;
NSLog(@"%f", randTime);
[self moveToSpriteNode:target withTimeInterval:randTime];
}];
//SKAction *repeatAction = [SKAction repeatAction:action count:6];
SKAction *rep = [SKAction sequence:@[action, action, action, action, action]]; //Test Sequence
[self runAction:rep completion:^{
[self runAction:blackColorAction];
_isAggravated = NO;
}];
}
I want my actions to actually wait until the previous action is done. Meaning, my actions need to be sequenced such that the rep
action doesn't repeat the action
action until the object FINISHES moving. Currently, it seems like the output immediately runs all the actions and doesn't sequence them like it should. I have read the documentation and what I have now is what they said to do...
The runBlock:
action is a fire-once type of action. It will run the block exactly once, then the action "ends" immediately afterwards.
What you want is something actions aren't designed to handle. They run once, or for a given period of time (duration). They don't, however, run until some arbitrary condition is met - which may be true immediately, may become true eventually or may never become true. This kind of invalidates all variable timing features actions are capable of (ie linear vs ease scaling of time).
What you can do is to issue the "moveToSpriteNode" movement as an action, and separately check in an update method whether the sprite has arrived at the node. If so, you'd run the next movement action (not using a sequence).
More easily you can simply rely on the move action to end meaning that the sprite has arrived at the target node. Then that would trigger the next move action in the sequence. If you want to run a completion block at each target, just schedule the next move action from within the completion block.