2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-04-25 17:07:15 +00:00
|
|
|
var BuildGameObject = require('../../BuildGameObject');
|
2018-01-16 22:28:29 +00:00
|
|
|
var GameObjectCreator = require('../../GameObjectCreator');
|
2017-09-14 01:27:29 +00:00
|
|
|
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param {object} config - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Text} The Game Object that was created.
|
|
|
|
*/
|
2017-09-14 01:27:29 +00:00
|
|
|
GameObjectCreator.register('text', function (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);
|
|
|
|
|
|
|
|
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.
|