MCPcopy Create free account
hub / github.com/melonjs/melonJS / loadCharacter

Function loadCharacter

packages/examples/src/examples/spine/ExampleSpine.tsx:23–56  ·  view source on GitHub ↗
(char: (typeof characters)[number])

Source from the content-addressed store, hash-verified

21let currentSpine: InstanceType<typeof Spine> | null = null;
22
23const 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
58const createGame = () => {
59 if (app) {

Callers 2

createGameFunction · 0.85
CharacterSelectorFunction · 0.85

Calls 5

setSkinByNameMethod · 0.95
scaleMethod · 0.95
setAnimationMethod · 0.95
removeChildMethod · 0.80
addChildMethod · 0.80

Tested by

no test coverage detected