Macilias Macilias - 1 year ago 152
Objective-C Question

SKAction how to combine withKey and completion

I´m quite new to iOS and Sprite Kit programming and wonder how to combine:

-[SKAction runAction:withKey:]


-[SKAction runAction:completion:]

On the one side, I want to prevent a node from running the same action (or action sequence) again, on the other, I want to react to the termination of an action, but there is no method and, as far as I see, no way to use both at the same time.


Answer Source

Use +runBlock: action in +sequence: like this:

SKAction *yourAction = ...

SKAction *completion = [SKAction runBlock:^{
    // Your code.
SKAction *sequence = [SKAction sequence:@[ yourAction, completion ]];

[node runAction:sequence withKey:yourKey];

If you use this multiple times, create SKNode category with such method:

- (void)runAction:(SKAction *)action withKey:(NSString *)key completion:(void(^)(void))block;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download