0

this is my third attempt of trying to solve the problem with the delay of runAction with completion.

Iv'e done some testing and gotten this far. I hope someone can tell me if there is some setting or other that creates this delay.

I started a new sprite kit project and added this. It works great. Smooth movement.

But when I add a "hero" node and this code into my existing project it stops for a millisecond between the action and the completion.

Is there anyone that knows why?

-(void)loopTest {
SKAction *move = [SKAction moveTo:CGPointMake(hero.position.x+32, hero.position.y) duration:0.7];
[hero runAction:move completion:^{
[self loopTest];
}];
}
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Znyder
  • 51
  • 7
  • Oh I see it. It's possible that due to the completion block running after actions have been evaluated this frame, the next action won't run until the next frame. Therefore you have a 1-frame delay in which the node stops. Try using a runBlock action rather than the completion block. – CodeSmile Oct 21 '14 at 09:37
  • loopTest is called once from didmovetoview and the moves the hero a bit each time. When the action is over it calls loopTest again and moves the hero again (just for test). The millisecond is not a precise measurement but the paus is cleary visible and doesbt create a smooth movement. – Znyder Oct 21 '14 at 09:39
  • I updated my comment, refresh the page in your browser. ;) – CodeSmile Oct 21 '14 at 10:08
  • Haha, using the app on iphone :) I will try the runBlock to see if it will smooth things out. Will post when I do, at work right now. Thanks – Znyder Oct 21 '14 at 10:39
  • This might sound like a stupid fix, but did you account for the .7 duration of your action? Completion means that it will wait for the .7 seconds it has to move. Other than that, why are you calling loopTest again when you can use `[hero runAction[SKAction repeatActionForever:move]];` or the `repeatAction: count:` counterpart? The delay may be caused from you calling the method again instead of just redoing the action – Andriko13 Oct 26 '14 at 02:09

1 Answers1

1

I rebuilt the app from scratch (time consuming...) but the problem was presentScene..

I used ResizeFill instead of AspectFill.. When I changed it, no more freezing problems.

Znyder
  • 51
  • 7