Hoisted the fillRect/canvasRect/pxRound flags to the CanvasRenderer.
This commit is contained in:
parent
b757e652e9
commit
723c5ca525
4 changed files with 33 additions and 19 deletions
|
@ -41,21 +41,6 @@ PIXI.scaleModes = {
|
||||||
NEAREST:1
|
NEAREST:1
|
||||||
};
|
};
|
||||||
|
|
||||||
// Canvas specific controls
|
|
||||||
PIXI.canvas = {
|
|
||||||
|
|
||||||
// If the Stage is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color.
|
|
||||||
// Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set.
|
|
||||||
FILL_RECT: true,
|
|
||||||
|
|
||||||
// If the Stage is transparent Pixi will use clearRect to clear the canvas every frame.
|
|
||||||
// Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set.
|
|
||||||
CLEAR_RECT: true,
|
|
||||||
|
|
||||||
// If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation. Handy for crisp pixel art and speed on legacy devices.
|
|
||||||
PX_ROUND: false
|
|
||||||
}
|
|
||||||
|
|
||||||
// interaction frequency
|
// interaction frequency
|
||||||
PIXI.INTERACTION_FREQUENCY = 30;
|
PIXI.INTERACTION_FREQUENCY = 30;
|
||||||
PIXI.AUTO_PREVENT_DEFAULT = true;
|
PIXI.AUTO_PREVENT_DEFAULT = true;
|
|
@ -345,7 +345,7 @@ PIXI.Sprite.prototype._renderCanvas = function(renderSession)
|
||||||
|
|
||||||
// allow for trimming
|
// allow for trimming
|
||||||
|
|
||||||
if (PIXI.canvas.PX_ROUND)
|
if (renderSession.roundPixels)
|
||||||
{
|
{
|
||||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
|
||||||
|
|
||||||
// alow for trimming
|
// alow for trimming
|
||||||
|
|
||||||
if (PIXI.canvas.PX_ROUND)
|
if (renderSession.roundPixels)
|
||||||
{
|
{
|
||||||
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
context.setTransform(transform.a, transform.c, transform.b, transform.d, Math.floor(transform.tx), Math.floor(transform.ty));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,35 @@ PIXI.CanvasRenderer = function(width, height, view, transparent)
|
||||||
|
|
||||||
this.type = PIXI.CANVAS_RENDERER;
|
this.type = PIXI.CANVAS_RENDERER;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the Stage is NOT transparent Pixi will use a canvas sized fillRect operation every frame to set the canvas background color.
|
||||||
|
* Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set.
|
||||||
|
*
|
||||||
|
* @property useFillRect
|
||||||
|
* @type Boolean
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
this.useFillRect = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the Stage is transparent Pixi will use clearRect to clear the canvas every frame.
|
||||||
|
* Disable this by setting this to false. For example if your game has a canvas filling background image you often don't need this set.
|
||||||
|
*
|
||||||
|
* @property useClearRect
|
||||||
|
* @type Boolean
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
this.useClearRect = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true Pixi will Math.floor() x/y values when rendering, stopping pixel interpolation.
|
||||||
|
* Handy for crisp pixel art and speed on legacy devices.
|
||||||
|
*
|
||||||
|
* @property roundPixels
|
||||||
|
* @type Boolean
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
this.roundPixels = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the render view is transparent
|
* Whether the render view is transparent
|
||||||
|
@ -165,12 +194,12 @@ PIXI.CanvasRenderer.prototype.render = function(stage)
|
||||||
this.context.setTransform(1,0,0,1,0,0);
|
this.context.setTransform(1,0,0,1,0,0);
|
||||||
this.context.globalAlpha = 1;
|
this.context.globalAlpha = 1;
|
||||||
|
|
||||||
if (!this.transparent && PIXI.canvas.FILL_RECT)
|
if (!this.transparent && this.useFillRect)
|
||||||
{
|
{
|
||||||
this.context.fillStyle = stage.backgroundColorString;
|
this.context.fillStyle = stage.backgroundColorString;
|
||||||
this.context.fillRect(0, 0, this.width, this.height);
|
this.context.fillRect(0, 0, this.width, this.height);
|
||||||
}
|
}
|
||||||
else if (this.transparent && PIXI.canvas.CLEAR_RECT)
|
else if (this.transparent && this.useClearRect)
|
||||||
{
|
{
|
||||||
this.context.clearRect(0, 0, this.width, this.height);
|
this.context.clearRect(0, 0, this.width, this.height);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue