(char: (typeof characters)[number])
| 21 | let currentSpine: InstanceType<typeof Spine> | null = null; |
| 22 | |
| 23 | const loadCharacter = (char: (typeof characters)[number]) => { |
| 24 | if (!app) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // remove previous spine object |
| 29 | if (currentSpine) { |
| 30 | app.world.removeChild(currentSpine); |
| 31 | currentSpine = null; |
| 32 | } |
| 33 | |
| 34 | // create new spine renderable |
| 35 | const spineObj = new Spine(char.x, char.y, { |
| 36 | atlasFile: char.atlas, |
| 37 | jsonFile: char.json, |
| 38 | }); |
| 39 | |
| 40 | // set skin if specified |
| 41 | if ("skin" in char && char.skin) { |
| 42 | spineObj.setSkinByName(char.skin); |
| 43 | } |
| 44 | |
| 45 | // apply scale if specified |
| 46 | if ("scale" in char && char.scale) { |
| 47 | spineObj.scale(char.scale); |
| 48 | } |
| 49 | |
| 50 | // set default animation |
| 51 | spineObj.setAnimation(0, char.animation, true); |
| 52 | |
| 53 | // add to world |
| 54 | app.world.addChild(spineObj); |
| 55 | currentSpine = spineObj; |
| 56 | }; |
| 57 | |
| 58 | const createGame = () => { |
| 59 | if (app) { |
no test coverage detected