phaser/src/polyfills/Uint32Array.js
J.C 57dee7c461 1, add missing polyfill for IE9,10
2, IE9, 10, function alias causes error and all audio can't work properly
2021-12-21 17:09:55 +08:00

49 lines
1.4 KiB
JavaScript

/**
* 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' && typeof window.Uint32Array !== 'object')
{
var CheapArray = function (fakeType)
{
var proto = new Array(); // jshint ignore:line
window[fakeType] = function(arg) {
if (typeof(arg) === 'number')
{
Array.call(this, arg);
this.length = arg;
for (var i = 0; i < this.length; i++)
{
this[i] = 0;
}
}
else
{
Array.call(this, arg.length);
this.length = arg.length;
for (var i = 0; i < this.length; i++)
{
this[i] = arg[i];
}
}
};
window[fakeType].prototype = proto;
window[fakeType].constructor = window[fakeType];
};
CheapArray('Float32Array'); // jshint ignore:line
CheapArray('Uint32Array'); // jshint ignore:line
CheapArray('Uint16Array'); // jshint ignore:line
CheapArray('Int16Array'); // jshint ignore:line
CheapArray('ArrayBuffer'); // jshint ignore:line
CheapArray('Int8Array'); // jshint ignore:line
CheapArray('Uint8Array'); // jshint ignore:line
}