Skip to content

Commit 071d9cf

Browse files
committed
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 (phaserjs#1933)
1 parent 74fd042 commit 071d9cf

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
391391
* PIXI.WebGLGraphics.stencilBufferLimit is a new integer that allows you to define how many points exist in a Graphics object before Pixi swaps to using the Stencil Buffer to render it. The default is 6 but can be increased. This fixes issues with things like Quadratic curves not rendering as masks in WebGL.
392392
* 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)
393393
* The Filter Texture and GL Viewport are now properly resized, fixing issues with custom resolutions and filters (thanks @englercj @amadeus #2326 #2320)
394+
* 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)
394395

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

src/pixi/primitives/Graphics.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,19 +638,26 @@ PIXI.Graphics.prototype.clear = function()
638638
* This can be quite useful if your geometry is complicated and needs to be reused multiple times.
639639
*
640640
* @method generateTexture
641-
* @param resolution {Number} The resolution of the texture being generated
642-
* @param scaleMode {Number} Should be one of the PIXI.scaleMode consts
641+
* @param [resolution=1] {Number} The resolution of the texture being generated
642+
* @param [scaleMode=0] {Number} Should be one of the PIXI.scaleMode consts
643+
* @param [padding=0] {Number} Add optional extra padding to the generated texture (default 0)
643644
* @return {Texture} a texture of the graphics object
644645
*/
645-
PIXI.Graphics.prototype.generateTexture = function(resolution, scaleMode)
646+
PIXI.Graphics.prototype.generateTexture = function(resolution, scaleMode, padding)
646647
{
647-
resolution = resolution || 1;
648+
if (resolution === undefined) { resolution = 1; }
649+
if (scaleMode === undefined) { scaleMode = PIXI.scaleModes.DEFAULT; }
650+
if (padding === undefined) { padding = 0; }
648651

649652
var bounds = this.getBounds();
653+
654+
bounds.width += padding;
655+
bounds.height += padding;
650656

651657
var canvasBuffer = new PIXI.CanvasBuffer(bounds.width * resolution, bounds.height * resolution);
652658

653659
var texture = PIXI.Texture.fromCanvas(canvasBuffer.canvas, scaleMode);
660+
654661
texture.baseTexture.resolution = resolution;
655662

656663
canvasBuffer.context.scale(resolution, resolution);

0 commit comments

Comments
 (0)