On Sun, Jul 28, 2013 at 8:37 PM, Shinji K <[email protected]> wrote:
> I need to queue sequences of actions. As per the documentation, this works
> fine:
>
> sprite.do(action_1 + action_2)
>
> Now I've run into a situation where I need something a bit more flexible,
> e.g.:
>
> sprite.do(action_1)
> ...
> (other stuff)
> ...
> sprite.do(action_2)
>
> I.e. I want action_1 to run and then when it finishes it should run
> action_2. What currently happens is that it starts action_1 and immediately
> moves on to action_2 without completing action_1.
>
> Is there any way to queue the actions so that it will wait for action_1 to
> finish and only then run action_2?
> --
>
>
Not for generic nodes: a node can have many actions running in parallel, so
it is not clear what should be done then.
Also, when you do
worker_action = node.do(action_template)
the code behind does
worker_action.target = node
worker_action.start()
which poses the ambiguity about when you want the .start to be called: when
issuing the do ? after completing action 1 ?
If your special case does not need actions in parallel, something along
the lines of :
class SpriteWithQueuedActions(cocos.sprite.Sprite):
def __init__(*args, *kwargs):
super(SpriteWithQueuedActions).__init__(*args, **kwargs)
self.queued_actions = []
def queued_do(self, action, target=None):
if self.are_actions_running():
self.queued_actions.append(action)
else:
self.do( action + cocos.actions.CallFunc(self.on_action_end))
def on_action_end(self):
if self.queued_actions:
action = self.queued_actions.pop(0)
self.do( action + cocos.actions.CallFunc(self.on_action_end))
If you use .queued_do to run actions and never call directly .do , then
this may be near to what you want. (untested)
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.