Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Scene: detect when an action has finished processing
-
I am creating a turn based game and would like to run action sequences on SpriteNodes then once finished run some code then another action sequence.
Is it possible to detect when an action or action sequence has finished? In the documentation there seems to be a paused attribute for nodes. However, I didn’t seem to be able to get anything other than false before and after actions. Any help would be appreciated.
Thanks
-
If you want an Action to directly follow another Action, you use an Action.sequence to chain together two actions. But, if you don't know what the next action will be when you create it, you could use an Action.call in the sequence.
For instance, suppose you have an enemy which moves 10 steps, then when it is done moving, turns towards the player and moves again. you could set a .moving flag, then have a sequence that consists of
Action.sequence(Action.move_by(...), Action.call(done_moving) )
The second action could be an Action.call, which, for instance, simply sets a flag.
-
I launched an action to spin all the cards off the screen and then I wanted to put up a new start menu, but that wasn’t apparently a callable Object, so the menu pops up and the cards all get stuck half way through spinning off the screen.
Thanks for the other pointer tho’ I will explore the implications of that hint...
-
try looking at
Action.call(yourfunction)
-
Thank you for suggesting Action.call. This is exactly what I needed. I had overlooked this in the documentation.
In the end, I created a sub class of the SpriteNode and modified the run_action method to add an action.call at the beginning and end of the action sequence. So every card that gets animated adds it’s name to stack of actions that are currently animating.