diff --git a/packages/phaserx/src/createEmbodiedEntity.ts b/packages/phaserx/src/createEmbodiedEntity.ts index 8266557b3e..8b5fd4757b 100644 --- a/packages/phaserx/src/createEmbodiedEntity.ts +++ b/packages/phaserx/src/createEmbodiedEntity.ts @@ -63,13 +63,13 @@ export function createEmbodiedEntity( 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()); } } @@ -84,6 +84,7 @@ export function createEmbodiedEntity( gameObject.resetPipeline(true, true); gameObject.setScale(1, 1); gameObject.setOrigin(0, 0); + gameObject.setAlpha(1); if (isSprite(gameObject, type)) { gameObject.clearTint(); gameObject.setTexture(""); diff --git a/packages/phaserx/src/types.ts b/packages/phaserx/src/types.ts index ba6d532889..80c1db8c32 100644 --- a/packages/phaserx/src/types.ts +++ b/packages/phaserx/src/types.ts @@ -64,7 +64,7 @@ export type Input = ReturnType; export type EmbodiedEntity = { setComponent: (component: GameObjectComponent) => void; - removeComponent: (id: string) => void; + removeComponent: (id: string, stop?: boolean) => void; spawn: () => void; despawn: () => void; position: Coord; diff --git a/packages/phaserx/src/utils/tween.ts b/packages/phaserx/src/utils/tween.ts index af0b222625..b1c02c9b8f 100644 --- a/packages/phaserx/src/utils/tween.ts +++ b/packages/phaserx/src/utils/tween.ts @@ -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(); 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({