KoMo Posted April 22, 2015 Share Posted April 22, 2015 Hi Guys, I was looking for an answer but could not find one so Im sorry if I missed and double post. Im currently working on an small sidescroller game. The enemies are created as group and come from the right into the scene. what I would like to do is add a random name for the enemy displayed as text on top of the enemy,and having the same physical propperties like it (eg gets killed/destroyd if the enemy dies, moves at same speed etc)I suppose I can do this as child from the enemy but I have no idea how to add text this way especially for an "dynamic" text I appreciate any help cheers Link to comment Share on other sites More sharing options...
jeancode Posted April 23, 2015 Share Posted April 23, 2015 I think you can simply add your text as a child of your enemy sprite, e.g : // your text : play with the 'x' and 'y' to position your text above your enemy sprite var name = this.game.add.text(x, y, 'baddy', {font:'24px Arial', fill: '#FF0000', align: 'center'});name.anchor.set(0.5) // I suppose yourEnemy is a phaser sprite defined in your code yourEnemy.addChild(name); Now your text should position itself in relation to its parent. If you set x and y to 0, the center of your text should be positionned to the top-left of your enemy sprite Link to comment Share on other sites More sharing options...
MichaelD Posted April 23, 2015 Share Posted April 23, 2015 The above answer is the correct way, just mind that if you need to know the dimentions of the text you will need to addname.updateText(); before using name.width/height or name.textWidth/textHeight Link to comment Share on other sites More sharing options...
Recommended Posts