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

Method setSkeleton

packages/spine-plugin/src/Spine.js:210–256  ·  view source on GitHub ↗

* Set and load the given skeleton atlas and json definition files. * (use this if you did not specify any json or atlas through the constructor) * @param {string} atlasFile - the name of the atlasFile to be used to create this spine animation * @param {string} jsonFile - the name of the jsonFi

(atlasFile, jsonFile)

Source from the content-addressed store, hash-verified

208 * me.game.world.addChild(spineAlien);
209 */
210 setSkeleton(atlasFile, jsonFile) {
211 // Create the texture atlas and skeleton data.
212 const atlas = this.plugin.assetManager.require(atlasFile);
213 const atlasLoader = new this.runtime.AtlasAttachmentLoader(atlas);
214 // pick the binary or json reader based on file extension — the asset
215 // manager already loads .skel as a Uint8Array and .json as text, so
216 // we just need to dispatch to the matching SkeletonReader
217 const isBinary = jsonFile.endsWith(".skel");
218 const skeletonReader = isBinary
219 ? new this.runtime.SkeletonBinary(atlasLoader)
220 : new this.runtime.SkeletonJson(atlasLoader);
221 const skeletonData = skeletonReader.readSkeletonData(
222 this.plugin.assetManager.require(jsonFile),
223 );
224
225 // detect premultiplied alpha from atlas pages
226 this.premultipliedAlpha = atlas.pages.some((page) => {
227 return page.pma;
228 });
229 this.skeletonRenderer.premultipliedAlpha = this.premultipliedAlpha;
230
231 // Instantiate a new skeleton based on the atlas and skeleton data.
232 this.skeleton = new this.runtime.Skeleton(skeletonData);
233
234 // auto-detect if the skeleton uses mesh attachments for canvas renderer
235 if (!this.isWebGL) {
236 this.skeletonRenderer.triangleRendering = skeletonData.skins.some(
237 (skin) => {
238 return skin.getAttachments().some((entry) => {
239 return entry.attachment instanceof MeshAttachment;
240 });
241 },
242 );
243 }
244
245 this.setToSetupPose();
246
247 // Setup an animation state with a default mix of 0.2 seconds.
248 const animationStateData = new this.runtime.AnimationStateData(
249 this.skeleton.data,
250 );
251 animationStateData.defaultMix = this.mixTime;
252 this.animationState = new this.runtime.AnimationState(animationStateData);
253
254 // get a reference to the root bone
255 this.root = this.skeleton.getRootBone();
256 }
257
258 /**
259 * Flip the Spine skeleton on the horizontal axis (around its root bone).

Callers 1

constructorMethod · 0.95

Calls 2

setToSetupPoseMethod · 0.95
requireMethod · 0.80

Tested by

no test coverage detected