Skip to content

Commit

Permalink
fix(phaserx): allow for multiple tweens on same objects by passing in… (
Browse files Browse the repository at this point in the history
#122)

* fix(phaserx): allow for multiple tweens on same objects by passing in control flags

* fix(phaserx): fix breaking change on embodiedEntity.removeComponent

* fix: make stop flag optional in types

Co-authored-by: alvarius <89248902+alvrs@users.noreply.github.com>
  • Loading branch information
davidkol and alvrs authored Aug 5, 2022
1 parent 4eac3c6 commit d129836
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/phaserx/src/createEmbodiedEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ export function createEmbodiedEntity<Type extends keyof GameObjectTypes>(
if (activeGameObject && once) once(activeGameObject);
}

function removeComponent(id: string) {
function removeComponent(id: string, stop?: boolean) {
onOnce.delete(id);
onUpdate.delete(id);

// Reset the entity and reapply all onOnce components
if (activeGameObject) {
reset(activeGameObject, false);
reset(activeGameObject, stop);
executeGameObjectFunctions(activeGameObject, onOnce.values());
}
}
Expand All @@ -84,6 +84,7 @@ export function createEmbodiedEntity<Type extends keyof GameObjectTypes>(
gameObject.resetPipeline(true, true);
gameObject.setScale(1, 1);
gameObject.setOrigin(0, 0);
gameObject.setAlpha(1);
if (isSprite(gameObject, type)) {
gameObject.clearTint();
gameObject.setTexture("");
Expand Down
2 changes: 1 addition & 1 deletion packages/phaserx/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type Input = ReturnType<typeof createInput>;

export type EmbodiedEntity<Type extends keyof GameObjectTypes> = {
setComponent: (component: GameObjectComponent<Type>) => void;
removeComponent: (id: string) => void;
removeComponent: (id: string, stop?: boolean) => void;
spawn: () => void;
despawn: () => void;
position: Coord;
Expand Down
6 changes: 4 additions & 2 deletions packages/phaserx/src/utils/tween.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ type TweenBuilderConfig = { targets: Phaser.GameObjects.Sprite } & Omit<
* Add a tween to the provided game object.
* @returns Promise that resolves when the tween is done.
*/
export async function tween(config: TweenBuilderConfig) {
export async function tween(config: TweenBuilderConfig, options?: { keepExistingTweens?: boolean }) {
const [resolve, , promise] = deferred<void>();
const { targets } = config;
if (!targets.scene || !targets.scene.tweens) return;

// Kill old tweens
removeAllTweens(targets);
if (!options?.keepExistingTweens) {
removeAllTweens(targets);
}

// Add new tween
targets.scene.tweens.add({
Expand Down

0 comments on commit d129836

Please sign in to comment.