Composing actions after started

8 views
Skip to first unread message

Facundo Batista

unread,
Nov 1, 2020, 10:21:58 AM11/1/20
to cocos-...@googlegroups.com
Hello!

I want the effect of "composing" a second action with the current
one... I'll describe an example to show that better:

I press UP and my sprite will jump (I'm using JumpBy for this), and in
the middle of the jump, I press RIGHT and I want to move the sprite
some pixels to the right, in the middle of the jump!

IOW, the sequence would be something like (showing simple X Y of the sprite)

Just jumping:

- t0: 0, 0
- UP
- t1: 0, 2
- t2: 0, 3
- t3: 0, 2
- t4: 0, 0

Pressing RIGHT in the middle of the jump:

- t0: 0, 0
- UP
- t1: 0, 2
- t2: 0, 3
- RIGHT
- t3: 1, 2
- t4: 1, 0

My problem is that when doing mysprit.do(MoveBy((1, 0), 0)) when the
use presses RIGHT it *interrupts* the jump.

Is there a way to not interrupt the current action and run the second
action in parallel with the rest of the current one?

Thanks!

--
. Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org.ar/
Twitter: @facundobatista

claudio canepa

unread,
Nov 1, 2020, 9:47:33 PM11/1/20
to cocos2d discuss

>Is there a way to not interrupt the current action and run the second
action in parallel with the rest of the current one? 

Not with the current codebase.  See api/cocos.actions.base_actions.html#restrictions-and-capabilities-for-the-current-design-and-implementation (you need to build the docs, I don't have a live link now, sorry)

There you can see an inspiration for a possible workaround: look at class MoveByAdditive, if you write a JumpAdditive then it can compose with another additive or instant action as you described,

Not ideal but the most immediate solution.


Long term, maybe a new action operation over Actions could be defined
      worker_action = actor.do(Jump(...))
      actor.do(Modify( worker_action,  fn_my_action_patcher)

where Modify should extract init params from the worker action, calculate remaining_duration, call the user provided   fn_my_action_patcher with those params,  the fn must return the desired composition.

Looks not easy to use, but maybe some experimentation can produce something viable.




--
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 cocos-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocos-discuss/CAM09pzQkvJQ-t%2BzL1ZaMV%2BKgWpEs%2B2trrtZB5cAauJOpd4XR8g%40mail.gmail.com.

claudio canepa

unread,
Nov 2, 2020, 8:06:22 AM11/2/20
to cocos2d discuss
>  (you need to build the docs, I don't have a live link now, sorry)

or download the source package from pypi, in includes the rendered docs

Facundo Batista

unread,
Nov 2, 2020, 4:56:12 PM11/2/20
to cocos-...@googlegroups.com
El dom., 1 de nov. de 2020 a la(s) 23:47, claudio canepa
(ccan...@gmail.com) escribió:

> There you can see an inspiration for a possible workaround: look at class MoveByAdditive, if you write a JumpAdditive then it can compose with another additive or instant action as you described,
>
> Not ideal but the most immediate solution.
>
>
> Long term, maybe a new action operation over Actions could be defined
> worker_action = actor.do(Jump(...))
> actor.do(Modify( worker_action, fn_my_action_patcher)
>
> where Modify should extract init params from the worker action, calculate remaining_duration, call the user provided fn_my_action_patcher with those params, the fn must return the desired composition.
>
> Looks not easy to use, but maybe some experimentation can produce something viable.

Wonderful, thanks!
Reply all
Reply to author
Forward
0 new messages