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.Action.group and scene.Node.paused not working ?
-
Hi everyone,
Today i was doing some tests on scene.Action capabilities, but I sruggled with two weirds behaviours of actions:- Node.paused boolean does not seems to be locked in 'false' state, not changing when executing an action or not; however it is also possible that I didn't understood this attribute. testing code...
from scene import * class Main(Scene): def setup(self): self.background_color = '#cdcdcd' self.char = SpriteNode('plf:AlienBlue_stand', x_scale = 3, y_scale =3) self.char.position = (512,384) self.add_child(self.char) print(self.char.paused, 'a') self.char.run_action(Action.move_by(0,-100,1.0)) print(self.char.paused, 'b') run(Main())
...which would presumably give us a False then a True. but we get two 'False'. Try it by yourself and tell me if you get others results !
2) When I use a Action.group of two Actions which would negate themselves, only the second one is taken into account; testing code...class Main(Scene): def setup(self): self.background_color = '#cdcdcd' self.char = SpriteNode('plf:AlienBlue_stand', x_scale = 3, y_scale =3) self.char.position = (512,384) self.add_child(self.char) def touch_began(self,touch): action_group = Action.group(Action.move_by(0,100),Action.move_by(0,-100)) if not self.char.paused: self.char.run_action(action_group) run(Main())
... and for output I let you try it by yourself too. Have a nice day/night,
Thanks in advance,
SmartGoat -
paused
is a boolean that YOU set. If you want actions to stop, you set paused=True. It won't ever change on its own. -
@JonB First, thanks for answering me.
Second, Crap ! It's much less usable than i thought. So there isn't any way to know if a given Node is executing an action ?
Cordially,
SmartGoat -
@SmartGoat you could begin and terminate your actions group by an action.call to a code where you set/reset a global variable telling you if the actions are ended
-
I vaguely recall that in scene.py, the underlying action logic is exposed, and there might be an actions dict that you can query. Will look tonight.
If you just want to stop whatever actions are happening, you can name your actions using the key parameter in run_action, so run action with the same key stops the current action. Or, you can use remove_action with the key.
-
@SmartGoat About Action.group, read carefully its help, could it be possible that you want run an Action.sequence, it a group because your two actions run simultaneously in a group thus the longer one could seem to be alone to run.
-
@cvp I just wanted to test action.group, not especially do an action.sequence. It is just strange that if the two actions are running simultaneously and they theorically negate themselves, why wouldn't the character stay in place ?
-
@SmartGoat I can't answer to this question. Here a little script to use Action.call to be able to check if an Action runs
from scene import * from objc_util import * def action_begin_call(node,progress): node.active = True def action_end_call(node,progress): node.active = False class Main(Scene): def setup(self): self.background_color = '#cdcdcd' self.char = SpriteNode('plf:AlienBlue_stand', x_scale = 3, y_scale =3) self.char.active = False self.char.position = (512,384) self.add_child(self.char) def touch_began(self,touch): if not self.char.active: action_group = Action.sequence( # Action.call needs a duration to force # function to receive node # duration small so function called only once Action.call(action_begin_call,0.001), Action.move_by(0,100), Action.move_by(0,-100), Action.call(action_end_call,0.001)) self.char.run_action(action_group) run(Main())
Or
action_group = Action.sequence( # Action.call needs a duration to force # function to receive node # duration small so function called only once Action.call(action_begin_call,0.001), Action.group( Action.move_by(0,100), Action.move_by(0,-100)), Action.call(action_end_call,0.001)) self.char.run_action(action_group)
-
It is possible that an action.group you cannot change the same parameter in different actions. But if you use two run_actions back to back, they both run.
-
@JonB I suppose you're right. I forget always that an action is only an animation due to change only one attribute of the node...Ha la la, my memory....👴🏻+👳🏼♂️