2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2023-01-02 17:36:27 +00:00
|
|
|
* @copyright 2013-2023 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
|
|
|
*/
|
|
|
|
|
2020-10-13 10:04:46 +00:00
|
|
|
var BuildGameObject = require('../BuildGameObject');
|
|
|
|
var GameObjectCreator = require('../GameObjectCreator');
|
|
|
|
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
|
2017-09-14 01:27:29 +00:00
|
|
|
var Text = require('./Text');
|
|
|
|
|
2018-02-07 00:18:22 +00:00
|
|
|
/**
|
|
|
|
* Creates a new Text Game Object and returns it.
|
|
|
|
*
|
|
|
|
* Note: This method will only be available if the Text Game Object has been built into Phaser.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.GameObjectCreator#text
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2020-08-01 11:34:07 +00:00
|
|
|
* @param {Phaser.Types.GameObjects.Text.TextConfig} config - The configuration object this Game Object will use to create itself.
|
2018-05-02 09:57:26 +00:00
|
|
|
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
|
2018-02-07 00:18:22 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The Game Object that was created.
|
|
|
|
*/
|
2018-05-02 09:57:26 +00:00
|
|
|
GameObjectCreator.register('text', function (config, addToScene)
|
2017-04-25 17:07:15 +00:00
|
|
|
{
|
2018-05-16 14:17:08 +00:00
|
|
|
if (config === undefined) { config = {}; }
|
|
|
|
|
2017-04-25 17:07:15 +00:00
|
|
|
// style Object = {
|
|
|
|
// font: [ 'font', '16px Courier' ],
|
|
|
|
// backgroundColor: [ 'backgroundColor', null ],
|
|
|
|
// fill: [ 'fill', '#fff' ],
|
|
|
|
// stroke: [ 'stroke', '#fff' ],
|
|
|
|
// strokeThickness: [ 'strokeThickness', 0 ],
|
|
|
|
// shadowOffsetX: [ 'shadow.offsetX', 0 ],
|
|
|
|
// shadowOffsetY: [ 'shadow.offsetY', 0 ],
|
|
|
|
// shadowColor: [ 'shadow.color', '#000' ],
|
|
|
|
// shadowBlur: [ 'shadow.blur', 0 ],
|
|
|
|
// shadowStroke: [ 'shadow.stroke', false ],
|
|
|
|
// shadowFill: [ 'shadow.fill', false ],
|
|
|
|
// align: [ 'align', 'left' ],
|
|
|
|
// maxLines: [ 'maxLines', 0 ],
|
|
|
|
// fixedWidth: [ 'fixedWidth', false ],
|
|
|
|
// fixedHeight: [ 'fixedHeight', false ],
|
|
|
|
// rtl: [ 'rtl', false ]
|
|
|
|
// }
|
|
|
|
|
|
|
|
var content = GetAdvancedValue(config, 'text', '');
|
|
|
|
var style = GetAdvancedValue(config, 'style', null);
|
|
|
|
|
2017-04-25 18:46:13 +00:00
|
|
|
// Padding
|
2017-11-30 17:16:38 +00:00
|
|
|
// { padding: 2 }
|
|
|
|
// { padding: { x: , y: }}
|
|
|
|
// { padding: { left: , top: }}
|
|
|
|
// { padding: { left: , right: , top: , bottom: }}
|
2017-04-25 18:46:13 +00:00
|
|
|
|
|
|
|
var padding = GetAdvancedValue(config, 'padding', null);
|
|
|
|
|
2017-11-30 17:16:38 +00:00
|
|
|
if (padding !== null)
|
2017-04-25 18:46:13 +00:00
|
|
|
{
|
2017-12-01 03:11:23 +00:00
|
|
|
style.padding = padding;
|
2017-04-25 18:46:13 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 03:11:23 +00:00
|
|
|
var text = new Text(this.scene, 0, 0, content, style);
|
|
|
|
|
2018-05-02 09:57:26 +00:00
|
|
|
if (addToScene !== undefined)
|
|
|
|
{
|
|
|
|
config.add = addToScene;
|
|
|
|
}
|
|
|
|
|
2017-12-01 03:11:23 +00:00
|
|
|
BuildGameObject(this.scene, text, config);
|
|
|
|
|
|
|
|
// Text specific config options:
|
|
|
|
|
|
|
|
text.autoRound = GetAdvancedValue(config, 'autoRound', true);
|
|
|
|
text.resolution = GetAdvancedValue(config, 'resolution', 1);
|
2017-04-25 18:46:13 +00:00
|
|
|
|
2017-04-25 17:07:15 +00:00
|
|
|
return text;
|
2017-09-14 01:27:29 +00:00
|
|
|
});
|
2018-02-07 00:18:22 +00:00
|
|
|
|
|
|
|
// When registering a factory function 'this' refers to the GameObjectCreator context.
|