Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Text 如何在变量中组合文本属性以全局使用?_Text_Combinations_Phaser Framework - Fatal编程技术网

Text 如何在变量中组合文本属性以全局使用?

Text 如何在变量中组合文本属性以全局使用?,text,combinations,phaser-framework,Text,Combinations,Phaser Framework,如何在变量中组合文本属性以全局使用 提前感谢您的帮助 var text = game.add.text(game.world.centerX, game.world.centerY + 50, 'Challenge your friends!'); text.font = 'Arial'; // here it is the property of phaser text.fontSize = '12px'; // here it is the property of phas

如何在变量中组合文本属性以全局使用

提前感谢您的帮助

var text = game.add.text(game.world.centerX, game.world.centerY + 50, 'Challenge your friends!');
    text.font = 'Arial'; // here it is the property of phaser
    text.fontSize = '12px';  // here it is the property of phaser
    text.align = 'center'; // here it is the property of phaser
    text.fontWeight = 'bold'; // here it is the property of phaser

如果我理解您的问题,您只需要利用文本构造函数使用的样式对象。看

您可以在某处创建全局变量,例如:

GLOBAL_TEXTSTYLE = {font : '12px Arial', font-weight: 'bold', align: 'center' };
然后在函数调用中使用它:

var text = game.add.text(game.world.centerX, game.world.centerY + 50,
                         'Challenge your friends!', GLOBAL_TEXTSTYLE);
有些人将这样的东西存储在游戏对象的属性中。您有可能与游戏的其他属性发生名称冲突,但您可以通过以下方式实现:

 // Create an object to store my game variables
 game.myGlobals = {};
 game.myGlobals.textStyle = {font:'12px Arial', font-weight:'bold', align:'center' };
然后使用它:

 var text = game.add.text(game.world.centerX, game.world.centerY + 50, 
                          'Challenge your friends!', game.myGlobals.textStyle);