Skip to content

Commit

Permalink
Fixed and tested on IE9.
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Apr 29, 2014
1 parent 75a848f commit 9fd4ac5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 66 deletions.
46 changes: 31 additions & 15 deletions src/gameobjects/BitmapData.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,28 +65,37 @@ Phaser.BitmapData = function (game, key, width, height) {
*/
this.imageData = this.context.getImageData(0, 0, width, height);

/**
* @property {Uint8ClampedArray} data - A Uint8ClampedArray view into BitmapData.buffer.
*/
this.data = this.imageData.data;

/**
* @property {Uint32Array} pixels - An Uint32Array view into BitmapData.buffer.
*/
this.pixels = null;

/**
* @property {ArrayBuffer} buffer - An ArrayBuffer the same size as the context ImageData.
*/
if (this.imageData.data.buffer)
{
this.buffer = this.imageData.data.buffer;
this.pixels = new Uint32Array(this.buffer);
}
else
{
this.buffer = new ArrayBuffer(this.imageData.data.length);
if (window['ArrayBuffer'])
{
this.buffer = new ArrayBuffer(this.imageData.data.length);
this.pixels = new Uint32Array(this.buffer);
}
else
{
this.pixels = this.imageData.data;
}
}

/**
* @property {Uint8ClampedArray} data - A Uint8ClampedArray view into BitmapData.buffer.
*/
this.data = this.imageData.data;

/**
* @property {Uint32Array} pixels - An Uint32Array view into BitmapData.buffer.
*/
this.pixels = new Uint32Array(this.buffer);

/**
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
* @default
Expand Down Expand Up @@ -265,19 +274,26 @@ Phaser.BitmapData.prototype = {
if (typeof height === 'undefined') { height = this.height; }

this.imageData = this.context.getImageData(x, y, width, height);
this.data = this.imageData.data;

if (this.imageData.data.buffer)
{
this.buffer = this.imageData.data.buffer;
this.pixels = new Uint32Array(this.buffer);
}
else
{
this.buffer = new ArrayBuffer(this.imageData.data.length);
if (window['ArrayBuffer'])
{
this.buffer = new ArrayBuffer(this.imageData.data.length);
this.pixels = new Uint32Array(this.buffer);
}
else
{
this.pixels = this.imageData.data;
}
}

this.data = this.imageData.data;
this.pixels = new Uint32Array(this.buffer);

},

/**
Expand Down
98 changes: 47 additions & 51 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,60 +320,56 @@ if (!Array.prototype.forEach)
};
}

(function(global, undefined) {
/**
* Low-budget Float32Array knock-off, suitable for use with P2.js in IE9
* Source: http://www.html5gamedevs.com/topic/5988-phaser-12-ie9/
* Cameron Foale (http://www.kibibu.com)
*/
if (typeof global.Uint32Array !== "function")
/**
* Low-budget Float32Array knock-off, suitable for use with P2.js in IE9
* Source: http://www.html5gamedevs.com/topic/5988-phaser-12-ie9/
* Cameron Foale (http://www.kibibu.com)
*/
if (typeof window.Uint32Array !== "function")
{
var CheapArray = function(type)
{
var CheapArray = function(type)
{
var proto = new Array(); // jshint ignore:line

global[type] = function(arg) {

if (typeof(arg) === "number")
var proto = new Array(); // jshint ignore:line

window[type] = function(arg) {

if (typeof(arg) === "number")
{
Array.call(this, arg);
this.length = arg;

for (var i = 0; i < this.length; i++)
{
Array.call(this, arg);
this.length = arg;

for (var i = 0; i < this.length; i++)
{
this[i] = 0;
}
this[i] = 0;
}
else
{
Array.call(this, arg.length);
}
else
{
Array.call(this, arg.length);

this.length = arg.length;

for (var i = 0; i < this.length; i++)
{
this[i] = arg[i];
}
this.length = arg.length;

for (var i = 0; i < this.length; i++)
{
this[i] = arg[i];
}
};

global[type].prototype = proto;
global[type].constructor = global[type];
}
};

CheapArray('Uint32Array'); // jshint ignore:line
CheapArray('Int16Array'); // jshint ignore:line
}

/**
* Also fix for the absent console in IE9
*/
if (!window.console)
{
window.console = {};
window.console.log = window.console.assert = function(){};
window.console.warn = window.console.assert = function(){};
}

})(this);

window[type].prototype = proto;
window[type].constructor = window[type];
};

CheapArray('Uint32Array'); // jshint ignore:line
CheapArray('Int16Array'); // jshint ignore:line
}

/**
* Also fix for the absent console in IE9
*/
if (!window.console)
{
window.console = {};
window.console.log = window.console.assert = function(){};
window.console.warn = window.console.assert = function(){};
}

0 comments on commit 9fd4ac5

Please sign in to comment.