I can call
- (void)runAction:(SKAction *)action completion:(void (^)(void))block
but how to call one completion block after running an action on 4 different SKNode
s?
basically what I need is to perform some action once this method has been called on all 4 SKNode
- (void)rotateToSquareIndex:(SquareIndex)squareIndex
{
self.squareIndex = squareIndex;
int index = self.index;
SKAction * action;
switch (squareIndex)
{
case indexTopLeft:
action = [SKAction moveTo:CGPointMake(16.f, 16.f) duration:.3];
index -= 1;
break;
case indexTopRight:
action = [SKAction moveTo:CGPointMake(48.f, 16.f) duration:.3];
index += 10;
break;
case indexBottomRight:
action = [SKAction moveTo:CGPointMake(48.f, 48.f) duration:.3];
index += 1;
break;
case indexBottomLeft:
action = [SKAction moveTo:CGPointMake(16.f, 48.f) duration:.3];
index -= 10;
break;
default:
break;
}
self.index = index;
[self runAction:action];
}
OK, I don't think there's any built in or "sexy" way of achieving what you're after, but here's at least a solution I believe should work:
You need a mutable array, a private property if you write code the way I do, squareIndexesRotated
- (void)rotateToSquareIndex:(SquareIndex)squareIndex
{
self.squareIndex = squareIndex;
int index = self.index;
NSNumber *indexNumber = [NSNumber numberWithInt:index];
if (![self.squareIndexesRotated containsObject:indexNumber]){
[self.squareIndexesRotated addObject:indexNumber];
}
// your action + switch stuff
if ([self.squareIndexesRotated count] == 4){
// Do whatever you want here...
}
}
Looks like your trying to do something like this.
YourAction = [SKAction moveTo:CGPointMake(100, 280)duration:5.0];
SKAction *completion = [SKAction runBlock:^{
}];
SKAction *sequence = [SKAction sequence:@[ YourActions ,etc... ]];
[YourNode runAction:sequence];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.