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

This commit is contained in:
Richard Davey 2018-09-27 16:49:52 +01:00
parent 5ad4c8dc2b
commit 3944e580cc
5 changed files with 14 additions and 4 deletions

View file

@ -51,6 +51,7 @@
* 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)
* 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)
* 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.
* There is a new Animation Event that is dispatched when an animation restarts. Listen for it via `Sprite.on('animationrestart')`.
* All of the Animation Events now pass the Game Object as the final argument, this includes `animationstart`, `animationrestart`, `animationrepeat`, `animationupdate` and `animationcomplete`.
### Bug Fixes
@ -64,6 +65,7 @@
* 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.
* The `Texture.getFramesFromTextureSource` method was returning an array of Frame names by mistake, instead of Frame references. It now returns the Frames themselves.
* 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)
* 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)
### Examples, Documentation and TypeScript

View file

@ -968,6 +968,11 @@ var Animation = new Class({
gameObject.texture = animationFrame.frame.texture;
gameObject.frame = animationFrame.frame;
if (gameObject.isCropped)
{
gameObject.frame.updateCropUVs(gameObject._crop, gameObject.flipX, gameObject.flipY);
}
gameObject.setSizeToFrame();
if (animationFrame.frame.customPivot)

View file

@ -549,8 +549,8 @@ var CanvasRenderer = new Class({
var frameX = cd.x;
var frameY = cd.y;
var frameWidth = frame.width;
var frameHeight = frame.height;
var frameWidth = frame.cutWidth;
var frameHeight = frame.cutHeight;
var res = frame.source.resolution;
var x = -sprite.displayOriginX + frame.x;

View file

@ -376,8 +376,8 @@ var TextureTintPipeline = new Class({
var v1 = frame.v1;
var frameX = frame.x;
var frameY = frame.y;
var frameWidth = frame.width;
var frameHeight = frame.height;
var frameWidth = frame.cutWidth;
var frameHeight = frame.cutHeight;
var x = -sprite.displayOriginX + frameX;
var y = -sprite.displayOriginY + frameY;

View file

@ -502,6 +502,9 @@ var Frame = new Class({
// Need to check for intersection between the cut area and the crop area
// If there is none, we set UV to be empty, otherwise set it to be the intersection area
width = Clamp(width, 0, cw - x);
height = Clamp(height, 0, ch - y);
var cropRight = x + width;
var cropBottom = y + height;