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:
Richard Davey 2016-02-03 11:34:23 +00:00
parent 90ddfc2aa2
commit 8043d29aa6

View file

@ -45,7 +45,6 @@ Phaser.BitmapData = function (game, key, width, height) {
* @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws.
* @default
*/
// this.canvas = Phaser.Canvas.create(width, height, '', true);
this.canvas = PIXI.CanvasPool.create(this, width, height);
/**
@ -213,10 +212,10 @@ Phaser.BitmapData = function (game, key, width, height) {
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
*/
this._swapCanvas = PIXI.CanvasPool.create(this, width, height);
this._swapCanvas = undefined;
};
@ -263,6 +262,11 @@ Phaser.BitmapData.prototype = {
if (wrap === undefined) { wrap = true; }
if (this._swapCanvas === undefined)
{
this._swapCanvas = PIXI.CanvasPool.create(this, this.width, this.height);
}
var c = this._swapCanvas;
var ctx = c.getContext('2d');
var h = this.height;
@ -321,6 +325,11 @@ Phaser.BitmapData.prototype = {
if (wrap === undefined) { wrap = true; }
if (this._swapCanvas === undefined)
{
this._swapCanvas = PIXI.CanvasPool.create(this, this.width, this.height);
}
var c = this._swapCanvas;
var ctx = c.getContext('2d');
var w = this.width;
@ -542,8 +551,11 @@ Phaser.BitmapData.prototype = {
this.canvas.width = width;
this.canvas.height = height;
this._swapCanvas.width = width;
this._swapCanvas.height = height;
if (this._swapCanvas !== undefined)
{
this._swapCanvas.width = width;
this._swapCanvas.height = height;
}
this.baseTexture.width = width;
this.baseTexture.height = height;