Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite kit SKAction repeatActionForever random wait duration

Tags:

sprite-kit

Thank you for helping first. The SKAction sequence looks like this:

SKAction *seq = [SKAction sequence:@[wait, throwAnim, run]];
SKAction *req = [SKAction repeatActionForever:seq];

Is there any way to make the wait a random duration, or can be controlled during the forever repeat?

like image 852
caoool Avatar asked Jan 18 '26 23:01

caoool


1 Answers

You can use waitForDuration:withRange:

Duration parameter represents average wait time, and range represents variation.

Each time the action is executed, the action computes a new random value for the duration. The duration may vary in either direction by up to half of the value of the durationRange parameter.

For example if you set duration to 5.0 and range to 2.0 you will get wait times between 4.0 and 6.0

like image 193
Dobroćudni Tapir Avatar answered Jan 20 '26 22:01

Dobroćudni Tapir