Action.repeat() won't repeat.
-
Hello, why won't "repmo" repeat itself?
I would like the action to continuously run after "phase_1", yet it only runs once. How do I fix this? Thank you.up = A.move_to(self.size.w/2, 350, 9,TIMING_EASE_BACK_OUT) mo = A.move_to(random.randrange(100,924),random.randrange(300,700), 2, TIMING_EASE_BACK_IN_OUT) repmo = A.repeat(mo, -1) phase_1 = A.sequence(stationary, up) #stationary appears earlier self.boss.run_action(A.sequence(phase_1, repmo))
This is only a snippet of code, I'm just highlighting the bits that need looking at. For example, although the code doesn't specify, A = Action.
-
The action does repeat, but the random coordinates are only calculated once, so each repetition moves to the same point (which has the same effect as if it wouldn't repeat at all).
If you want new random coordinates with every repetition, you'd need to use a custom
call
action.
-
Ahh, I understand that, thanks.
I'll have to do some more reading now, because the call function confuses me, it doesn't take much code does it? Could you give an example of how I would do it, if that isn't too much to ask?
But anyway, thanks, I'll look into it.
-
Something like this should work:
up = A.move_to(self.size.w/2, 350, 9, TIMING_EASE_BACK_OUT) d = 2.0 # duration # Inline function for the call action: def move_random(): x, y = random.randrange(100,924), random.randrange(300,700) self.boss.run_action(A.move_to(x, y, d)) # The call action doesn't wait until the move action finishes, so add a wait action for that: repmo = A.repeat(A.sequence(A.call(move_random), A.wait(d)), -1)) phase_1 = A.sequence(stationary, up) mo = A.move_to(, 2, TIMING_EASE_BACK_IN_OUT) self.boss.run_action(A.sequence(phase_1, repmo))
(I actually used a slightly simpler example for testing, so there might be some typos here)
-
Wow, thank you, that helps me a lot.
-
This post is deleted!last edited by Kamozo
-
Sorry, there's a closing parenthesis too much, it should be:
repmo = A.repeat(A.sequence(A.call(move_random), A.wait(d)), -1)
-
Oh yeah, I'm not sure how I didn't notice that.
Where does the code you've provided fit into mine?
-
This post is deleted!last edited by Kamozo
-
Nevermind, I've figured it.
Thanks for all your help.
-
@omz said:
Sorry, there's a closing parenthesis too much, it should be:
It sounds much less awkward to an American if you say "there's one too many closing parentheses," but not a big deal. Just putting it out there
-
I hadn't realised the
A.call()
thing existed - loads of possibilities for animations!