mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 21:24:09 +00:00
BitmapData would always create a private _swapCanvas
which was a clone of its main canvas used for advanced movement operations. This no longer happens. The swap canvas is created only as needed, by those functions that use it (specifically moveH
and moveV
), meaning a BitmapData will now use half the amount of memory it used to, and you'll have half the amount of canvas DOM elements created (unless you make heavy use of the move functions).
This commit is contained in:
parent
90ddfc2aa2
commit
8043d29aa6
1 changed files with 17 additions and 5 deletions
|
@ -45,7 +45,6 @@ Phaser.BitmapData = function (game, key, width, height) {
|
||||||
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
|
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
// this.canvas = Phaser.Canvas.create(width, height, '', true);
|
|
||||||
this.canvas = PIXI.CanvasPool.create(this, width, height);
|
this.canvas = PIXI.CanvasPool.create(this, width, height);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,10 +212,10 @@ Phaser.BitmapData = function (game, key, width, height) {
|
||||||
this._circle = new Phaser.Circle();
|
this._circle = new Phaser.Circle();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {HTMLCanvasElement} _swapCanvas - A swap canvas.
|
* @property {HTMLCanvasElement} _swapCanvas - A swap canvas. Used by moveH and moveV, created in those methods.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._swapCanvas = PIXI.CanvasPool.create(this, width, height);
|
this._swapCanvas = undefined;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -263,6 +262,11 @@ Phaser.BitmapData.prototype = {
|
||||||
|
|
||||||
if (wrap === undefined) { wrap = true; }
|
if (wrap === undefined) { wrap = true; }
|
||||||
|
|
||||||
|
if (this._swapCanvas === undefined)
|
||||||
|
{
|
||||||
|
this._swapCanvas = PIXI.CanvasPool.create(this, this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
var c = this._swapCanvas;
|
var c = this._swapCanvas;
|
||||||
var ctx = c.getContext('2d');
|
var ctx = c.getContext('2d');
|
||||||
var h = this.height;
|
var h = this.height;
|
||||||
|
@ -321,6 +325,11 @@ Phaser.BitmapData.prototype = {
|
||||||
|
|
||||||
if (wrap === undefined) { wrap = true; }
|
if (wrap === undefined) { wrap = true; }
|
||||||
|
|
||||||
|
if (this._swapCanvas === undefined)
|
||||||
|
{
|
||||||
|
this._swapCanvas = PIXI.CanvasPool.create(this, this.width, this.height);
|
||||||
|
}
|
||||||
|
|
||||||
var c = this._swapCanvas;
|
var c = this._swapCanvas;
|
||||||
var ctx = c.getContext('2d');
|
var ctx = c.getContext('2d');
|
||||||
var w = this.width;
|
var w = this.width;
|
||||||
|
@ -542,8 +551,11 @@ Phaser.BitmapData.prototype = {
|
||||||
this.canvas.width = width;
|
this.canvas.width = width;
|
||||||
this.canvas.height = height;
|
this.canvas.height = height;
|
||||||
|
|
||||||
this._swapCanvas.width = width;
|
if (this._swapCanvas !== undefined)
|
||||||
this._swapCanvas.height = height;
|
{
|
||||||
|
this._swapCanvas.width = width;
|
||||||
|
this._swapCanvas.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
this.baseTexture.width = width;
|
this.baseTexture.width = width;
|
||||||
this.baseTexture.height = height;
|
this.baseTexture.height = height;
|
||||||
|
|
Loading…
Reference in a new issue