I would like to run a repeating one SKAction, but with random values ββfor each repeat. I read this question here , which shows one way to do this. However, I want my sprite animations to be animated, rather than just changing their position. One of the solutions I came up with is to execute a sequence of actions, with the last action calling my move method recursively:
- (void)moveTheBomber {
__weak typeof(self) weakSelf = self;
float randomX =
SKAction *moveAction = [SKAction moveToX:randomX duration:0.25f];
SKAction *waitAction = [SKAction waitForDuration:0.15 withRange:0.4];
SKAction *completionAction = [SKAction customActionWithDuration:0 actionBlock:^(SKNode *node, CGFloat elapsedTime) {
[weakSelf moveTheBomber];
}];
SKAction *sequence = [SKAction sequence:@[moveAction, waitAction, completionAction]];
[self.bomber runAction:sequence];
}
A recursive call to this method feels icky to me, but given my limited experience with SpriteKit, it seemed like the most obvious way to accomplish this.
How can I endlessly animate the random movement of a sprite on the screen?