Вопрос

I need to keep a sequence from firing multiple times before the first sequence is complete. I tried to lock the sequence using a boolean but am unsuccessful.

Here is what I tried.

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.lockJump == false) {
        self.lockJump = true;
        SKAction *jumpUp = [SKAction moveByX: 0 y: 70.0 duration: 0.45];
        SKAction *jumpDown = [SKAction moveByX: 0 y: -70.0 duration: 0.25];
        [self.player runAction:[SKAction sequence:@[jumpUp, jumpDown]]];
        self.lockJump = false;
    }
}

I would speculate that sequence is considered done when jumpDown is called, rather than terminated. This would mean the jump is unlocking before it is completed. I think this could be achieved by checking the time between the last called time and current time and setting it equal to .7 seconds, but am unsure of how to most efficiently and successfully tackle this problem.

Это было полезно?

Решение

One solution would be to use +[SKAction runBlock:] to add "unlocking" to your action sequence as the last step:

SKAction * unlock = [SKAction runBlock:^{ self.lockJump = NO; }];
[self.player runAction:[SKAction sequence:@[jumpUp, jumpDown, unlock]]];

(Aside: use YES and NO for BOOLs.)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top