Parallel actions #2327
-
Hello 👋 - awesome engine! I've been trialing porting a few projects across and really enjoying it so far. One part has me a bit stumped. Is it possible to have actions operate in parallel? async takeDamage(): Promise<void> {
this.actions.clearActions();
await this.actions
.moveBy(vec(100, 0), 500)
.moveBy(vec(-100, 0), 500)
.toPromise();
} However, if I want to also fade the Actor at the same time, is that possible with the current API? Something like: async takeDamage(): Promise<void> {
this.actions.clearActions();
await this.actions
.moveBy(vec(100, 0), 500)
.moveBy(vec(-100, 0), 500)
.fade(0, 2000, 0) // where the third argument is the absolute offset - ie: the start of the "timeline"
.toPromise();
} I know this is potentially a hugggggge can of worms. The best example I know of is https://greensock.com/docs/v3/GSAP/Timeline , specifically the position parameter. Alternatively, is using an external tween engine on top of Excalibur an option? GSAP can technically tween any object value, the only downside I could imagine is GSAP's internal ticker is not in sync with Excalibur. But, maybe this is "ok" as long as there is zero expectation that the Actors under the "influence" of GSAP are not physics driven |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @chrisk-7777 Thanks for the kind words, glad you are enjoying excalibur so far! Parallel actions are something we've wanted for a while and recently just implemented and merged! #2322 These bits are pretty fresh so any feedback is very welcome. This feature is only available in the npm alpha packages at the moment, 0.27.0-alpha.472 should have the latest build. With the parallel actions alpha you might do something like this (One warning about async/await with `toPromise(), it will block until the action is complete so you might want to use the callback form depending on what you're doing): class MyActor extends ex.Actor {
constructor() {
super({
x: 50,
y: 50,
width: 100,
height: 100,
color: ex.Color.Green
});
}
async takeDamage(): Promise<void> {
const knockBackSequence = new ex.ActionSequence(this, ctx => {
ctx.moveBy(ex.vec(100, 0), 500)
ctx.moveBy(ex.vec(-100, 0), 500)
});
const fadeSequence = new ex.ActionSequence(this, ctx => {
// ctx.delay(100); // optionally delay 100 milliseconds
ctx.fade(0, 1000);
});
const parallel = new ex.ParallelActions([knockBackSequence, fadeSequence]);
// oops runAction() doesn't return the ActionContext will fix soon
this.actions.runAction(parallel);
await this.actions.toPromise();
}
}
var myActor = new MyActor();
game.add(myActor);
myActor.takeDamage(); TimelinesWow greensock is pretty cool! I'll need to check it out! The timelines idea in their docs is very interesting, potentially for excalibur. External tweeningTo your question about an external tweening engine, it might be possible! I'd say you're right on the mark with the excalibur clock, but it might be okay as long as the |
Beta Was this translation helpful? Give feedback.
Hi @chrisk-7777
Thanks for the kind words, glad you are enjoying excalibur so far!
Parallel actions are something we've wanted for a while and recently just implemented and merged! #2322 These bits are pretty fresh so any feedback is very welcome.
This feature is only available in the npm alpha packages at the moment, 0.27.0-alpha.472 should have the latest build.
With the parallel actions alpha you might do something like this (One warning about async/await with `toPromise(), it will block until the action is complete so you might want to use the callback form depending on what you're doing):