Skip to content

Commit 9fd4ac5

Browse files
committed
Fixed and tested on IE9.
1 parent 75a848f commit 9fd4ac5

2 files changed

Lines changed: 78 additions & 66 deletions

File tree

src/gameobjects/BitmapData.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,37 @@ Phaser.BitmapData = function (game, key, width, height) {
6565
*/
6666
this.imageData = this.context.getImageData(0, 0, width, height);
6767

68+
/**
69+
* @property {Uint8ClampedArray} data - A Uint8ClampedArray view into BitmapData.buffer.
70+
*/
71+
this.data = this.imageData.data;
72+
73+
/**
74+
* @property {Uint32Array} pixels - An Uint32Array view into BitmapData.buffer.
75+
*/
76+
this.pixels = null;
77+
6878
/**
6979
* @property {ArrayBuffer} buffer - An ArrayBuffer the same size as the context ImageData.
7080
*/
7181
if (this.imageData.data.buffer)
7282
{
7383
this.buffer = this.imageData.data.buffer;
84+
this.pixels = new Uint32Array(this.buffer);
7485
}
7586
else
7687
{
77-
this.buffer = new ArrayBuffer(this.imageData.data.length);
88+
if (window['ArrayBuffer'])
89+
{
90+
this.buffer = new ArrayBuffer(this.imageData.data.length);
91+
this.pixels = new Uint32Array(this.buffer);
92+
}
93+
else
94+
{
95+
this.pixels = this.imageData.data;
96+
}
7897
}
7998

80-
/**
81-
* @property {Uint8ClampedArray} data - A Uint8ClampedArray view into BitmapData.buffer.
82-
*/
83-
this.data = this.imageData.data;
84-
85-
/**
86-
* @property {Uint32Array} pixels - An Uint32Array view into BitmapData.buffer.
87-
*/
88-
this.pixels = new Uint32Array(this.buffer);
89-
9099
/**
91100
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
92101
* @default
@@ -265,19 +274,26 @@ Phaser.BitmapData.prototype = {
265274
if (typeof height === 'undefined') { height = this.height; }
266275

267276
this.imageData = this.context.getImageData(x, y, width, height);
277+
this.data = this.imageData.data;
268278

269279
if (this.imageData.data.buffer)
270280
{
271281
this.buffer = this.imageData.data.buffer;
282+
this.pixels = new Uint32Array(this.buffer);
272283
}
273284
else
274285
{
275-
this.buffer = new ArrayBuffer(this.imageData.data.length);
286+
if (window['ArrayBuffer'])
287+
{
288+
this.buffer = new ArrayBuffer(this.imageData.data.length);
289+
this.pixels = new Uint32Array(this.buffer);
290+
}
291+
else
292+
{
293+
this.pixels = this.imageData.data;
294+
}
276295
}
277296

278-
this.data = this.imageData.data;
279-
this.pixels = new Uint32Array(this.buffer);
280-
281297
},
282298

283299
/**

src/utils/Utils.js

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -320,60 +320,56 @@ if (!Array.prototype.forEach)
320320
};
321321
}
322322

323-
(function(global, undefined) {
324-
325-
/**
326-
* Low-budget Float32Array knock-off, suitable for use with P2.js in IE9
327-
* Source: http://www.html5gamedevs.com/topic/5988-phaser-12-ie9/
328-
* Cameron Foale (http://www.kibibu.com)
329-
*/
330-
if (typeof global.Uint32Array !== "function")
323+
/**
324+
* Low-budget Float32Array knock-off, suitable for use with P2.js in IE9
325+
* Source: http://www.html5gamedevs.com/topic/5988-phaser-12-ie9/
326+
* Cameron Foale (http://www.kibibu.com)
327+
*/
328+
if (typeof window.Uint32Array !== "function")
329+
{
330+
var CheapArray = function(type)
331331
{
332-
var CheapArray = function(type)
333-
{
334-
var proto = new Array(); // jshint ignore:line
335-
336-
global[type] = function(arg) {
337-
338-
if (typeof(arg) === "number")
332+
var proto = new Array(); // jshint ignore:line
333+
334+
window[type] = function(arg) {
335+
336+
if (typeof(arg) === "number")
337+
{
338+
Array.call(this, arg);
339+
this.length = arg;
340+
341+
for (var i = 0; i < this.length; i++)
339342
{
340-
Array.call(this, arg);
341-
this.length = arg;
342-
343-
for (var i = 0; i < this.length; i++)
344-
{
345-
this[i] = 0;
346-
}
343+
this[i] = 0;
347344
}
348-
else
349-
{
350-
Array.call(this, arg.length);
345+
}
346+
else
347+
{
348+
Array.call(this, arg.length);
351349

352-
this.length = arg.length;
353-
354-
for (var i = 0; i < this.length; i++)
355-
{
356-
this[i] = arg[i];
357-
}
350+
this.length = arg.length;
351+
352+
for (var i = 0; i < this.length; i++)
353+
{
354+
this[i] = arg[i];
358355
}
359-
};
360-
361-
global[type].prototype = proto;
362-
global[type].constructor = global[type];
356+
}
363357
};
364-
365-
CheapArray('Uint32Array'); // jshint ignore:line
366-
CheapArray('Int16Array'); // jshint ignore:line
367-
}
368-
369-
/**
370-
* Also fix for the absent console in IE9
371-
*/
372-
if (!window.console)
373-
{
374-
window.console = {};
375-
window.console.log = window.console.assert = function(){};
376-
window.console.warn = window.console.assert = function(){};
377-
}
378-
379-
})(this);
358+
359+
window[type].prototype = proto;
360+
window[type].constructor = window[type];
361+
};
362+
363+
CheapArray('Uint32Array'); // jshint ignore:line
364+
CheapArray('Int16Array'); // jshint ignore:line
365+
}
366+
367+
/**
368+
* Also fix for the absent console in IE9
369+
*/
370+
if (!window.console)
371+
{
372+
window.console = {};
373+
window.console.log = window.console.assert = function(){};
374+
window.console.warn = window.console.assert = function(){};
375+
}

0 commit comments

Comments
 (0)