Phaser.LoaderParser = { bitmapFont: function (xml, baseTexture, xSpacing, ySpacing){ return this.xmlBitmapFont(xml, baseTexture, xSpacing, ySpacing); } , xmlBitmapFont: function (xml, baseTexture, xSpacing, ySpacing){ var data = { } ; var info = _AN_Call_getelementsbytagname('getElementsByTagName', xml, 'info')[0]; var common = _AN_Call_getelementsbytagname('getElementsByTagName', xml, 'common')[0]; data.font = _AN_Call_getattribute('getAttribute', info, 'face'); data.size = parseInt(_AN_Call_getattribute('getAttribute', info, 'size'), 10); data.lineHeight = parseInt(_AN_Call_getattribute('getAttribute', common, 'lineHeight'), 10) + ySpacing; data.chars = { } ; var letters = _AN_Call_getelementsbytagname('getElementsByTagName', xml, 'char'); for (var i = 0; i < _AN_Read_length('length', letters); i++ ){ var charCode = parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'id'), 10); data.chars[charCode] = { x: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'x'), 10), y: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'y'), 10), width: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'width'), 10), height: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'height'), 10), xOffset: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'xoffset'), 10), yOffset: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'yoffset'), 10), xAdvance: parseInt(_AN_Call_getattribute('getAttribute', letters[i], 'xadvance'), 10) + xSpacing, kerning: { } } ; } var kernings = _AN_Call_getelementsbytagname('getElementsByTagName', xml, 'kerning'); for (i = 0; i < _AN_Read_length('length', kernings); i++ ){ var first = parseInt(_AN_Call_getattribute('getAttribute', kernings[i], 'first'), 10); var second = parseInt(_AN_Call_getattribute('getAttribute', kernings[i], 'second'), 10); var amount = parseInt(_AN_Call_getattribute('getAttribute', kernings[i], 'amount'), 10); data.chars[second].kerning[first] = amount; } return this.finalizeBitmapFont(baseTexture, data); } , jsonBitmapFont: function (json, baseTexture, xSpacing, ySpacing){ var data = { font: json.font.info._face, size: parseInt(json.font.info._size, 10), lineHeight: parseInt(json.font.common._lineHeight, 10) + ySpacing, chars: { } } ; json.font.chars["char"] .forEach(function parseChar(letter){ var charCode = parseInt(letter._id, 10); data.chars[charCode] = { x: parseInt(letter._x, 10), y: parseInt(letter._y, 10), width: parseInt(letter._width, 10), height: parseInt(letter._height, 10), xOffset: parseInt(letter._xoffset, 10), yOffset: parseInt(letter._yoffset, 10), xAdvance: parseInt(letter._xadvance, 10) + xSpacing, kerning: { } } ; } ); if (json.font.kernings && json.font.kernings.kerning) { json.font.kernings.kerning.forEach(function parseKerning(kerning){ data.chars[kerning._second].kerning[kerning._first] = parseInt(kerning._amount, 10); } ); } return this.finalizeBitmapFont(baseTexture, data); } , finalizeBitmapFont: function (baseTexture, bitmapFontData){ Object.keys(bitmapFontData.chars).forEach(function addTexture(charCode){ var letter = bitmapFontData.chars[charCode]; letter.texture = new PIXI.Texture(baseTexture, new Phaser.Rectangle(letter.x, letter.y, letter.width, letter.height)); } ); return bitmapFontData; } , pvr: function (arrayBuffer){ var uintArray = new Uint32Array(arrayBuffer.slice(0, 52)), byteArray = new Uint8Array(arrayBuffer), pvrHeader = null , pixelFormat = (uintArray[3] << 32 | uintArray[2]), compressionAlgorithm; if (uintArray[0] === 55727696 && [0, 1, 2, 3, 6, 7, 9, 11] .indexOf(pixelFormat) >= 0) { if (pixelFormat >= 0 && pixelFormat <= 3) { compressionAlgorithm = 'PVRTC'; } else if (pixelFormat >= 7 && pixelFormat <= 11) { compressionAlgorithm = 'S3TC'; } else if (pixelFormat == 6) { compressionAlgorithm = 'ETC1'; } pvrHeader = { fileFormat: 'PVR', compressionAlgorithm: compressionAlgorithm, flags: uintArray[1], pixelFormat: pixelFormat, colorSpace: uintArray[4], channelType: uintArray[5], height: uintArray[6], width: uintArray[7], depth: uintArray[8], numberOfSurfaces: uintArray[9], numberOfFaces: uintArray[10], numberOfMipmaps: uintArray[11], metaDataSize: uintArray[12], textureData: byteArray.subarray(52 + uintArray[12], byteArray.byteLength)} ; } return pvrHeader; } , dds: function (arrayBuffer){ var byteArray = new Uint8Array(arrayBuffer), uintArray = new Uint32Array(arrayBuffer), ddsHeader = null ; if (byteArray[0] === 68 && byteArray[1] === 68 && byteArray[2] === 83 && byteArray[3] === 32) { ddsHeader = { fileFormat: 'DDS', compressionAlgorithm: 'S3TC', size: uintArray[1], flags: uintArray[2], height: uintArray[3], width: uintArray[4], pitch: uintArray[5], depth: uintArray[6], mipmapCount: uintArray[7], formatSize: uintArray[19], formatFlag: uintArray[19], formatFourCC: [String.fromCharCode(byteArray[84]), String.fromCharCode(byteArray[85]), String.fromCharCode(byteArray[86]), String.fromCharCode(byteArray[87])] .join(''), formatBitCount: uintArray[21], formatRBitMask: uintArray[22], formatGBitMask: uintArray[23], formatBBitMask: uintArray[24], formatABitMask: uintArray[25], caps1: uintArray[26], caps2: uintArray[27], caps3: uintArray[28], caps4: uintArray[29], reserved2: uintArray[30], DXGIFormat: null , resourceDimension: null , miscFlag: null , arraySize: null , textureData: byteArray.subarray(uintArray[1] + 4, byteArray.byteLength)} ; if (ddsHeader.formatFourCC === 'DX10') { ddsHeader.DXGIFormat = uintArray[31]; ddsHeader.resourceDimension = uintArray[32]; ddsHeader.miscFlag = uintArray[33]; ddsHeader.arraySize = uintArray[34]; ddsHeader.miscFlag = uintArray[35]; } } return ddsHeader; } , ktx: function (arrayBuffer){ var byteArray = new Uint8Array(arrayBuffer), uintArray = new Uint32Array(arrayBuffer), ktxHeader = null , imageSizeOffset = 16 + (uintArray[15] / 4) | 0, imageSize = uintArray[imageSizeOffset], glInternalFormat = uintArray[7], compressionAlgorithm = 0; if (byteArray[0] === 171 && byteArray[1] === 75 && byteArray[2] === 84 && byteArray[3] === 88 && byteArray[4] === 32 && byteArray[5] === 49 && byteArray[6] === 49 && byteArray[7] === 187 && byteArray[8] === 13 && byteArray[9] === 10 && byteArray[10] === 26 && byteArray[11] === 10 && [36196, 35840, 35841, 35842, 35843, 33776, 33777, 33778, 33779] .indexOf(glInternalFormat) >= 0) { switch (glInternalFormat){ case 36196: compressionAlgorithm = 'ETC1'; break ; case 35840: case 35841: case 35842: case 35843: compressionAlgorithm = 'PVRTC'; break ; case 33776: case 33777: case 33778: case 33779: compressionAlgorithm = 'S3TC'; break ; } ktxHeader = { fileFormat: 'KTX', compressionAlgorithm: compressionAlgorithm, endianness: uintArray[3], glType: uintArray[4], glTypeSize: uintArray[5], glFormat: uintArray[6], glInternalFormat: uintArray[7], glBaseInternalFormat: uintArray[8], pixelWidth: uintArray[9], pixelHeight: uintArray[10], pixelDepth: uintArray[11], numberOfArrayElements: uintArray[12], numberOfFaces: uintArray[13], numberOfMipmapLevels: uintArray[14], bytesOfKeyValueData: uintArray[15], keyAndValueByteSize: uintArray[16], imageSize: imageSize, textureData: byteArray.subarray((imageSizeOffset + 1) * 4, imageSize + 100)} ; } return ktxHeader; } , pkm: function (arrayBuffer){ var byteArray = new Uint8Array(arrayBuffer), pkmHeader = null ; if (byteArray[0] === 80 && byteArray[1] === 75 && byteArray[2] === 77 && byteArray[3] === 32) { pkmHeader = { fileFormat: 'PKM', compressionAlgorithm: 'ETC1', format: ((byteArray[6] << 8 | byteArray[7])) & 65535, extendedWidth: ((byteArray[8] << 8 | byteArray[9])) & 65535, extendedHeight: ((byteArray[10] << 8 | byteArray[11])) & 65535, originalWidth: ((byteArray[12] << 8 | byteArray[13])) & 65535, originalHeight: ((byteArray[14] << 8 | byteArray[15])) & 65535, textureData: byteArray.subarray(16, _AN_Read_length('length', byteArray))} ; } return pkmHeader; } } ;