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

Method updateBounds

packages/melonjs/src/renderable/renderable.js:777–815  ·  view source on GitHub ↗

* update the bounding box for this shape. * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates * @returns {Bounds} this shape bounding box Rectangle object

(absolute = true)

Source from the content-addressed store, hash-verified

775 * @returns {Bounds} this shape bounding box Rectangle object
776 */
777 updateBounds(absolute = true) {
778 if (this.isRenderable) {
779 const bounds = this.getBounds();
780
781 bounds.clear();
782 if (this.autoTransform === true && !this.currentTransform.isIdentity()) {
783 // temporarily translate the matrix based on the anchor point
784 this.currentTransform.translate(
785 -this.width * this.anchorPoint.x,
786 -this.height * this.anchorPoint.y,
787 );
788 bounds.addFrame(0, 0, this.width, this.height, this.currentTransform);
789 this.currentTransform.translate(
790 this.width * this.anchorPoint.x,
791 this.height * this.anchorPoint.y,
792 );
793 } else {
794 bounds.addFrame(0, 0, this.width, this.height);
795 // translate the bounds based on the anchor point
796 bounds.translate(
797 -this.width * this.anchorPoint.x,
798 -this.height * this.anchorPoint.y,
799 );
800 }
801
802 if (absolute === true) {
803 const absPos = this.getAbsolutePosition();
804 bounds.centerOn(
805 absPos.x + bounds.x + bounds.width / 2,
806 absPos.y + bounds.y + bounds.height / 2,
807 );
808 }
809 return bounds;
810 } else {
811 // manage the case where updateBounds is called
812 // before the object being yet properly initialized
813 return super.updateBounds(absolute);
814 }
815 }
816
817 /**
818 * return the renderable absolute position in the game world. The

Callers 6

constructorMethod · 0.95
getBoundsMethod · 0.95
transformMethod · 0.95
rotateMethod · 0.95
scaleMethod · 0.95
translateMethod · 0.95

Calls 7

getBoundsMethod · 0.95
getAbsolutePositionMethod · 0.95
addFrameMethod · 0.80
clearMethod · 0.65
isIdentityMethod · 0.45
translateMethod · 0.45
centerOnMethod · 0.45

Tested by

no test coverage detected