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

fix(phaserx): allow for multiple tweens on same objects by passing in… #122

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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