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);