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

Method setRegion

packages/melonjs/src/renderable/frameAnimation.js:275–290  ·  view source on GitHub ↗

* apply a texture region as the current frame: store its geometry into * `current` and hand it to the host to draw (see Sprite#setRegion). * @param {object} region - the texture region object * @returns {object} the host (for method chaining)

(region)

Source from the content-addressed store, hash-verified

273 * @returns {object} the host (for method chaining)
274 */
275 setRegion(region) {
276 const current = this.current;
277 // set the frame offset within the texture
278 current.offset.setV(region.offset);
279 // set angle if defined
280 current.angle = typeof region.angle === "number" ? region.angle : 0;
281 // update the current frame size (trimmed dimensions, used for drawing)
282 current.width = region.width;
283 current.height = region.height;
284 // cache trim offset for drawing
285 current.trim = region.trim || null;
286 // hand the region to the host to apply to its own geometry; the host
287 // marks itself dirty inside `_applyFrame` (the engine owns no dirty flag)
288 this._applyFrame(region);
289 return this.host;
290 }
291
292 /**
293 * force the current animation frame index (see {@link Sprite#setAnimationFrame}).

Callers 1

setAnimationFrameMethod · 0.95

Calls 2

setVMethod · 0.45
_applyFrameMethod · 0.45

Tested by

no test coverage detected