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

Method updateBounds

packages/melonjs/src/renderable/entity/entity.js:303–327  ·  view source on GitHub ↗

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

(absolute = true)

Source from the content-addressed store, hash-verified

301 * @returns {Bounds} this entity bounding box Rectangle object
302 */
303 updateBounds(absolute = true) {
304 const bounds = this.getBounds();
305
306 bounds.clear();
307 bounds.addFrame(0, 0, this.width, this.height);
308
309 // add each renderable bounds
310 if (this.children && this.children.length > 0) {
311 bounds.addBounds(this.children[0].getBounds());
312 }
313
314 if (this.body) {
315 bounds.addBounds(this.body.getBounds());
316 }
317
318 if (absolute === true) {
319 const absPos = this.getAbsolutePosition();
320 bounds.centerOn(
321 absPos.x + bounds.x + bounds.width / 2,
322 absPos.y + bounds.y + bounds.height / 2,
323 );
324 }
325
326 return bounds;
327 }
328
329 /**
330 * update the bounds when the body is modified

Callers 2

renderableMethod · 0.95
onBodyUpdateMethod · 0.95

Calls 6

addFrameMethod · 0.80
addBoundsMethod · 0.80
getBoundsMethod · 0.65
clearMethod · 0.65
getAbsolutePositionMethod · 0.65
centerOnMethod · 0.45

Tested by

no test coverage detected