Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API actions.parallel #3084

Open
spustlik opened this issue May 30, 2024 · 2 comments
Open

New API actions.parallel #3084

spustlik opened this issue May 30, 2024 · 2 comments
Labels
proposal Applied to issues that are a proposal for an implementation stale This issue or PR has not had any activity recently

Comments

@spustlik
Copy link

spustlik commented May 30, 2024

Context

using paralel actions is different than using standard actions

Proposal

please consider to add new method to ActionContext probably .parallel() with inner context parameter like .repeat(),
where it will be possible to use fluent Action API
something like

myactor.actions
.paralel(ctx=>[
  ctx.moveTo(...),
  ctx.scaleTo(...),
]);

maybe it is possible to use generators with yield.

also usable should be shortcut for

myActor.actions.runAction(new ex.ParallelActions([ 
  new ex.MoveTo(...),
  new ex.ScaleTo(...)
])

to

myActor.actions.para(
  new ex.MoveTo(...),
  new ex.ScaleTo(...)
)
-- with para(...args:ex.Action[]) declaration
@eonarheim eonarheim added the proposal Applied to issues that are a proposal for an implementation label Jun 1, 2024
@eonarheim eonarheim changed the title actions.paralell New API actions.parallel Jun 1, 2024
@eonarheim
Copy link
Member

Hi @spustlik, I agree the current parallel actions is a bit clunky to use. I definitely think there is a better api here. Your proposal is interesting I'd like to play with it more 👍

myactor.actions
.paralel(ctx=>[
  ctx.moveTo(...),
  ctx.scaleTo(...),
]);

In the near term coroutines are a nice way to do more complicated animation simultaneously https://excaliburjs.com/docs/coroutines/

Here is an example doing some scaling on different axes at the same time

var newScaleBy = (actor: ex.Actor, scaleChange: ex.Vector, durationSeconds: number) => {
  // coroutines start automatically
  ex.coroutine(function* () {
    let duration = durationSeconds * 1000; // milliseconds
    let xScaleChangeRate = scaleChange.x / duration;
    let yScaleChangeRate = scaleChange.y / duration;
    let targetScale = actor.scale.add(scaleChange);
    while (duration > 0) {
      const elapsed = yield;
      duration -= elapsed;
      actor.scale.x += xScaleChangeRate * elapsed;
      actor.scale.y += yScaleChangeRate * elapsed;
    }
    actor.scale = targetScale;
  });
};

actor.onInitialize = () => {
  newScaleBy(actor, ex.vec(-0.5, -0.25), 2);
};

Copy link

github-actions bot commented Aug 1, 2024

This issue hasn't had any recent activity lately and is being marked as stale automatically.

@github-actions github-actions bot added the stale This issue or PR has not had any activity recently label Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Applied to issues that are a proposal for an implementation stale This issue or PR has not had any activity recently
Projects
None yet
Development

No branches or pull requests

2 participants