Skip to content

Commit 3944e58

Browse files
committed
Fixed an error in the batchSprite methods in the Canvas and WebGL Renderers that would incorrectly set the frame dimensions on Sprites with the crop component. This was particularly noticeable on Sprites with trimmed animation frames
1 parent 5ad4c8d commit 3944e58

5 files changed

Lines changed: 14 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* The Device.OS check for `node` will now do a `typeof` first to avoid issues with rollup packaged builds needing to shim the variable out. Fix #4058 (thanks @hollowdoor)
5252
* Arcade Physics Bodies will now sync the display origin of the parent Game Object to the body properties as part of the `updateBounds` call. This means if you change the origin of an AP enabled Game Object, after creation of the body, it will be reflected in the body position. This may or may not be a breaking change for your game. Previously it was expected that the origin should always be 0.5 and you adjust the body using `setOffset`, but this change makes a bit more sense logically. If you find that your bodies are offset after upgrading to this version then this is likely why. Close #4052 (thanks @SolarOmni)
5353
* The `Texture.getFramesFromTextureSource` method has a new boolean argument `includeBase`, which defaults to `false` and allows you to set if the base frame should be returned into the array or not.
54+
* There is a new Animation Event that is dispatched when an animation restarts. Listen for it via `Sprite.on('animationrestart')`.
5455
* All of the Animation Events now pass the Game Object as the final argument, this includes `animationstart`, `animationrestart`, `animationrepeat`, `animationupdate` and `animationcomplete`.
5556

5657
### Bug Fixes
@@ -64,6 +65,7 @@
6465
* When using `MatterGameObject` and `fromVerts` as the shape type it wouldn't pass the values to `Bodies.fromVertices` because of a previous conditional. It now passes them over correctly and the body is only set if the result is valid.
6566
* The `Texture.getFramesFromTextureSource` method was returning an array of Frame names by mistake, instead of Frame references. It now returns the Frames themselves.
6667
* When using `CanvasTexture.refresh` or `Graphics.generateTexture` it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix #4050 (thanks @kanthi0802)
68+
* Fixed an error in the `batchSprite` methods in the Canvas and WebGL Renderers that would incorrectly set the frame dimensions on Sprites with the crop component. This was particularly noticeable on Sprites with trimmed animation frames (thanks @sergeod9)
6769

6870
### Examples, Documentation and TypeScript
6971

src/gameobjects/components/Animation.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,11 @@ var Animation = new Class({
968968
gameObject.texture = animationFrame.frame.texture;
969969
gameObject.frame = animationFrame.frame;
970970

971+
if (gameObject.isCropped)
972+
{
973+
gameObject.frame.updateCropUVs(gameObject._crop, gameObject.flipX, gameObject.flipY);
974+
}
975+
971976
gameObject.setSizeToFrame();
972977

973978
if (animationFrame.frame.customPivot)

src/renderer/canvas/CanvasRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ var CanvasRenderer = new Class({
549549

550550
var frameX = cd.x;
551551
var frameY = cd.y;
552-
var frameWidth = frame.width;
553-
var frameHeight = frame.height;
552+
var frameWidth = frame.cutWidth;
553+
var frameHeight = frame.cutHeight;
554554
var res = frame.source.resolution;
555555

556556
var x = -sprite.displayOriginX + frame.x;

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ var TextureTintPipeline = new Class({
376376
var v1 = frame.v1;
377377
var frameX = frame.x;
378378
var frameY = frame.y;
379-
var frameWidth = frame.width;
380-
var frameHeight = frame.height;
379+
var frameWidth = frame.cutWidth;
380+
var frameHeight = frame.cutHeight;
381381

382382
var x = -sprite.displayOriginX + frameX;
383383
var y = -sprite.displayOriginY + frameY;

src/textures/Frame.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,9 @@ var Frame = new Class({
502502
// Need to check for intersection between the cut area and the crop area
503503
// If there is none, we set UV to be empty, otherwise set it to be the intersection area
504504

505+
width = Clamp(width, 0, cw - x);
506+
height = Clamp(height, 0, ch - y);
507+
505508
var cropRight = x + width;
506509
var cropBottom = y + height;
507510

0 commit comments

Comments
 (0)