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

Method update

packages/melonjs/src/renderable/sprite.js:705–735  ·  view source on GitHub ↗

* update function. * automatically called by the game manager game * @protected * @param {number} dt - time since the last update in milliseconds. * @returns {boolean} true if the Sprite is dirty

(dt)

Source from the content-addressed store, hash-verified

703 * @returns {boolean} true if the Sprite is dirty
704 */
705 update(dt) {
706 // play/pause video if necessary
707 if (this.isVideo) {
708 if (this.animationpause) {
709 this.image.pause();
710 } else if (this.image.paused) {
711 this.image.play();
712 }
713 this.isDirty = !this.image.paused;
714 } else {
715 // advance the shared frame-animation engine; a frame change marks this
716 // sprite dirty via `_applyFrame` (the engine owns no dirty flag)
717 this._frameAnim.update(dt);
718 }
719
720 //update the "flickering" state if necessary
721 if (this._flicker.isFlickering) {
722 this._flicker.elapsed += dt;
723 if (this._flicker.elapsed >= this._flicker.duration) {
724 if (typeof this._flicker.callback === "function") {
725 this._flicker.callback();
726 }
727 this.flicker(-1);
728 }
729 this.isDirty = true;
730 }
731
732 // `isDirty` is the single source of truth — sub-updates above set it,
733 // `Renderable.update` returns it
734 return super.update(dt);
735 }
736
737 /**
738 * Prepare the rendering context before drawing this sprite (automatically called by melonJS).

Callers

nothing calls this directly

Calls 3

flickerMethod · 0.95
pauseMethod · 0.45
playMethod · 0.45

Tested by

no test coverage detected