excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.77k stars 189 forks source link

[Proposal] Refactor Actions to make use of async/await for greater composibility #1177

Open eonarheim opened 5 years ago

eonarheim commented 5 years ago

Context

Currently the Actions API uses a fluent API that doesn't easily allow the user to compose simultaneous actions or to know when they are completed.

Proposal

Taking inspiration from Xamarin.Forms, thanks @alanag13 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/simple#composite-animations

I propose a new Action API

Actions would still be accessed off of the actions component of an entity

const actor = new ex.Actor({pos: ex.Vector.Zero, width: 10, height: 10});

// Move actor one action at a time serially

// Move actor to position (200, 200) in world space at 100 pixels/sec
let moveToComplete = await actor.actions.moveTo(200, 200, 100);

// Move actor relative to it's current position to the right 100 at 100 pixels/sec
let moveByComplete = await actor.actions.moveBy(100, 0, 100);

// Move actor and rotate concurrently

// Move actor to position (0, 0) in world space and rotate to PI/2 at the same time
let moveToAndRotateComplete = await Promise.all([
 actor.actions.moveTo(0, 0, 200),
 actor.actions.rotateTo(Math.PI / 2, .2)
]);
github-actions[bot] commented 3 years ago

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