SKAction repeatAction withKey和完成?

时间:2015-03-22 22:43:41

标签: objective-c sprite-kit skaction

我有一个SKAction:
SKAction *myAction = [SKAction performSelector:@selector(methodA) onTarget:self];

我希望在完成50个操作后调用methodB之前重复此操作50次。

[[self runAction:[SKAction repeatAction:myAction count:50]  
withKey:@"myActionKey"]   
 completion:^{
        [self methodB];
    }];

它给了我一个bad receiver type 'void'错误。如果我取出withKey:@"myActionKey"部分但我需要获取密钥,则错误消失,因为我可能需要在某个时候调用removeActionForKey:@"myActionKey"

有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您要执行的命令不存在,但您可以执行此操作:

SKAction *callMethodA = [SKAction runBlock:^{
    [self methodA];
}];

SKAction *myAction = [SKAction repeatAction:callMethodA count:50];

SKAction *callMethodB = [SKAction runBlock:^{
    [self methodB];
}];

SKAction *sequence = [SKAction sequence:@[myAction, callMethodB]];

[self runAction:sequence withKey:@"myKey"];