From 5a47ac00e81d80852e8928fa43049c42aedc6795 Mon Sep 17 00:00:00 2001 From: kts of kettek Date: Sat, 29 Jan 2022 17:05:42 -0800 Subject: [PATCH] Allow changing sprite ctor --- Engine/src/shared/sprites.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Engine/src/shared/sprites.ts b/Engine/src/shared/sprites.ts index 8b64a79..4fd35a4 100644 --- a/Engine/src/shared/sprites.ts +++ b/Engine/src/shared/sprites.ts @@ -10,19 +10,26 @@ for (let [key, value] of Object.entries(assets)) { export class SpriteInstance { container: PIXI.Container - sprite: Sprite + sprite: Sprite|null = null + spriteKey: string = '' animation?: SpritePart - animationKey: string + animationKey: string = '' set?: SpritePart - setKey: string + setKey: string = '' subset?: SpritePart - subsetKey: string + subsetKey: string = '' frame?: SpritePart - frameIndex: number + frameIndex: number = 0 constructor(ctor: string) { this.container = new PIXI.Container() + this.setCtor(ctor) + } + + setCtor(ctor: string) { + this.container.removeChildren() let [spriteKey, animationKey, setKey, subsetKey, frameKey] = ctor.split('.') + this.spriteKey = spriteKey this.animationKey = animationKey this.setKey = setKey this.subsetKey = subsetKey