* Apply the current frame's texture region to this sprite's geometry: swap * the source sub-texture, then resolve size / anchor (honoring trimming). * Invoked by the shared FrameAnimation engine via `setRegion`. * @param {object} region - the texture region object * @ignore
(region)
| 624 | * @ignore |
| 625 | */ |
| 626 | _applyFrame(region) { |
| 627 | // set the source texture for the given region |
| 628 | this.image = this.source.getTexture(region); |
| 629 | |
| 630 | if (region.trimmed && region.sourceSize) { |
| 631 | // use the original untrimmed size for stable bounds across trimmed frames |
| 632 | this.width = region.sourceSize.w; |
| 633 | this.height = region.sourceSize.h; |
| 634 | // recover the original pivot relative to sourceSize for stable anchor |
| 635 | if (region.anchorPoint) { |
| 636 | const pivotX = |
| 637 | (region.trim.x + region.width * region.anchorPoint.x) / this.width; |
| 638 | const pivotY = |
| 639 | (region.trim.y + region.height * region.anchorPoint.y) / this.height; |
| 640 | this.anchorPoint.setMuted( |
| 641 | this._flip.x ? 1 - pivotX : pivotX, |
| 642 | this._flip.y ? 1 - pivotY : pivotY, |
| 643 | ); |
| 644 | } |
| 645 | } else { |
| 646 | this.width = region.width; |
| 647 | this.height = region.height; |
| 648 | if (region.anchorPoint) { |
| 649 | this.anchorPoint.setMuted( |
| 650 | this._flip.x && region.trimmed === true |
| 651 | ? 1 - region.anchorPoint.x |
| 652 | : region.anchorPoint.x, |
| 653 | this._flip.y && region.trimmed === true |
| 654 | ? 1 - region.anchorPoint.y |
| 655 | : region.anchorPoint.y, |
| 656 | ); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | // update the sprite bounding box |
| 661 | this.updateBounds(); |
| 662 | // the frame changed → this sprite needs a redraw (the host owns its |
| 663 | // dirty flag; the FrameAnimation engine never sets it) |
| 664 | this.isDirty = true; |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * force the current animation frame index. |
no test coverage detected