Skip to content

Commit f6d273c

Browse files
committed
DisplayObject._generateCachedSprite (which is called from updateCache or when cacheAsBitmap is enabled) would bitwise | 1 the bounds width and height. This would often lead to incorrect rounding (heights of 4 would become 5, while heights of 5 would remain 5). This has now been removed and the width and height are passed through Mail.ceil and then checked to make sure they aren't less than 1 pixel in either direction (thanks @alesdotio phaserjs#2078)
1 parent b629539 commit f6d273c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
395395
* If a Display Object with a mask contained a child with a Filter, then the child would not render. The WebGLFilterManager now retains state and creates a new stencil buffer as required (thanks @hightopo #1842)
396396
* The Filter Texture and GL Viewport are now properly resized, fixing issues with custom resolutions and filters (thanks @englercj @amadeus #2326 #2320)
397397
* Graphics.generateTexture has a new argument `padding` which allows you to add extra spacing onto the generated texture. This is useful for small Graphics objects where you find a few pixels getting sliced off the edges due to rounding issues (#1933)
398+
* DisplayObject._generateCachedSprite (which is called from `updateCache` or when `cacheAsBitmap` is enabled) would bitwise | 1 the bounds width and height. This would often lead to incorrect rounding (heights of 4 would become 5, while heights of 5 would remain 5). This has now been removed and the width and height are passed through Mail.ceil and then checked to make sure they aren't less than 1 pixel in either direction (thanks @alesdotio #2078)
398399

399400
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
400401

src/pixi/display/DisplayObject.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,17 +641,21 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()
641641

642642
var bounds = this.getLocalBounds();
643643

644+
// Round it off and force non-zero dimensions
645+
bounds.width = Math.max(1, Math.ceil(bounds.width));
646+
bounds.height = Math.max(1, Math.ceil(bounds.height));
647+
644648
this.updateTransform();
645649

646650
if (!this._cachedSprite)
647651
{
648-
var renderTexture = new PIXI.RenderTexture(bounds.width | 1, bounds.height | 1);
652+
var renderTexture = new PIXI.RenderTexture(bounds.width, bounds.height);
649653
this._cachedSprite = new PIXI.Sprite(renderTexture);
650654
this._cachedSprite.worldTransform = this.worldTransform;
651655
}
652656
else
653657
{
654-
this._cachedSprite.texture.resize(bounds.width | 1, bounds.height | 1);
658+
this._cachedSprite.texture.resize(bounds.width, bounds.height);
655659
}
656660

657661
// Remove filters
@@ -664,8 +668,8 @@ PIXI.DisplayObject.prototype._generateCachedSprite = function()
664668
PIXI.DisplayObject._tempMatrix.ty = -bounds.y;
665669

666670
this._cachedSprite.texture.render(this, PIXI.DisplayObject._tempMatrix, true);
667-
this._cachedSprite.anchor.x = -( bounds.x / bounds.width );
668-
this._cachedSprite.anchor.y = -( bounds.y / bounds.height );
671+
this._cachedSprite.anchor.x = -(bounds.x / bounds.width);
672+
this._cachedSprite.anchor.y = -(bounds.y / bounds.height);
669673

670674
this._filters = tempFilters;
671675

0 commit comments

Comments
 (0)