2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-07-11 23:49:20 +00:00
|
|
|
var ParseXMLBitmapFont = require('./ParseXMLBitmapFont');
|
|
|
|
|
2018-03-16 17:29:39 +00:00
|
|
|
/**
|
2018-06-01 14:21:10 +00:00
|
|
|
* Parse an XML Bitmap Font from an Atlas.
|
2018-03-16 17:29:39 +00:00
|
|
|
*
|
2018-06-06 15:58:48 +00:00
|
|
|
* Adds the parsed Bitmap Font data to the cache with the `fontName` key.
|
|
|
|
*
|
2018-03-16 17:29:39 +00:00
|
|
|
* @function ParseFromAtlas
|
|
|
|
* @since 3.0.0
|
|
|
|
* @private
|
2018-06-01 14:21:10 +00:00
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - The Scene to parse the Bitmap Font for.
|
|
|
|
* @param {string} fontName - The key of the font to add to the Bitmap Font cache.
|
|
|
|
* @param {string} textureKey - The key of the BitmapFont's texture.
|
|
|
|
* @param {string} frameKey - The key of the BitmapFont texture's frame.
|
|
|
|
* @param {string} xmlKey - The key of the XML data of the font to parse.
|
2019-12-18 11:22:30 +00:00
|
|
|
* @param {integer} [xSpacing] - The x-axis spacing to add between each letter.
|
|
|
|
* @param {integer} [ySpacing] - The y-axis spacing to add to the line height.
|
2018-06-06 15:58:48 +00:00
|
|
|
*
|
|
|
|
* @return {boolean} Whether the parsing was successful or not.
|
2018-03-16 17:29:39 +00:00
|
|
|
*/
|
2017-07-14 13:30:20 +00:00
|
|
|
var ParseFromAtlas = function (scene, fontName, textureKey, frameKey, xmlKey, xSpacing, ySpacing)
|
2017-07-11 23:49:20 +00:00
|
|
|
{
|
2017-07-14 13:30:20 +00:00
|
|
|
var frame = scene.sys.textures.getFrame(textureKey, frameKey);
|
|
|
|
var xml = scene.sys.cache.xml.get(xmlKey);
|
2017-07-11 23:49:20 +00:00
|
|
|
|
|
|
|
if (frame && xml)
|
|
|
|
{
|
|
|
|
var data = ParseXMLBitmapFont(xml, xSpacing, ySpacing, frame);
|
|
|
|
|
2017-07-14 13:30:20 +00:00
|
|
|
scene.sys.cache.bitmapFont.add(fontName, { data: data, texture: textureKey, frame: frameKey });
|
2017-07-11 23:49:20 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ParseFromAtlas;
|