* 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)
| 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 |