phaser/src/polyfills/Uint32Array.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-11-22 03:11:33 +00:00
/**
* 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)
*/
2018-03-19 13:45:00 +00:00
if (typeof window.Uint32Array !== 'function' && typeof window.Uint32Array !== 'object')
2016-11-22 03:11:33 +00:00
{
2018-03-19 13:45:00 +00:00
var CheapArray = function (fakeType)
2016-11-22 03:11:33 +00:00
{
var proto = new Array(); // jshint ignore:line
2018-03-19 13:45:00 +00:00
window[fakeType] = function(arg) {
2016-11-22 03:11:33 +00:00
2018-03-19 13:45:00 +00:00
if (typeof(arg) === 'number')
2016-11-22 03:11:33 +00:00
{
Array.call(this, arg);
2018-03-19 13:45:00 +00:00
2016-11-22 03:11:33 +00:00
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];
}
}
};
2018-03-19 13:45:00 +00:00
window[fakeType].prototype = proto;
window[fakeType].constructor = window[fakeType];
2016-11-22 03:11:33 +00:00
};
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
2016-11-22 03:11:33 +00:00
}