* Update the bounding box for this spine object. * (this will automatically update the bounds of the entire skeleton animation) * @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates * @returns {Bounds} this shape bounding box Rectangle object
(absolute = true)
| 319 | * @returns {Bounds} this shape bounding box Rectangle object |
| 320 | */ |
| 321 | updateBounds(absolute = true) { |
| 322 | if (this.isRenderable) { |
| 323 | const bounds = this.getBounds(); |
| 324 | const isIdentity = |
| 325 | this.autoTransform === true && this.currentTransform.isIdentity(); |
| 326 | |
| 327 | bounds.clear(); |
| 328 | |
| 329 | if (typeof this.skeleton !== "undefined") { |
| 330 | this.skeleton.getBounds(this.boneOffset, this.boneSize, tempArray); |
| 331 | |
| 332 | // getBounds returns world-space coords; convert back to local |
| 333 | // space by subtracting the skeleton position we set in update(). |
| 334 | const minX = this.boneOffset.x - this.skeleton.x; |
| 335 | const minY = this.boneOffset.y - this.skeleton.y; |
| 336 | |
| 337 | bounds.addFrame( |
| 338 | minX, |
| 339 | minY, |
| 340 | minX + this.boneSize.x, |
| 341 | minY + this.boneSize.y, |
| 342 | !isIdentity ? this.currentTransform : undefined, |
| 343 | ); |
| 344 | } else { |
| 345 | bounds.addFrame( |
| 346 | 0, |
| 347 | 0, |
| 348 | this.width, |
| 349 | this.height, |
| 350 | !isIdentity ? this.currentTransform : undefined, |
| 351 | ); |
| 352 | } |
| 353 | |
| 354 | if (absolute === true) { |
| 355 | const absPos = this.getAbsolutePosition(); |
| 356 | bounds.centerOn(absPos.x + bounds.centerX, absPos.y + bounds.centerY); |
| 357 | } |
| 358 | return bounds; |
| 359 | } else { |
| 360 | // manage the case where updateBounds is called |
| 361 | // before the object being yet properly initialized |
| 362 | return super.updateBounds(absolute); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Update function (automatically called by melonJS). |
no test coverage detected