Ninjadoodle Posted July 10, 2018 Share Posted July 10, 2018 Hi @enpu I'm having a little bit of trouble with aligning text. I have a countdown time which basically starts at 20 and counts down to 0. Th issue I'm having is that it's always either left / right justified, when it get's updated. Do I need to manually recenter the text every time it gets updated with a new number? This is the code I'm using to set it up. (I've tried both 'align' and 'anchor' separately). this.countdownTxt = new game.Text('20', { align: 'center' }); this.countdownTxt.anchor.set(this.countdownTxt.width / 2, this.countdownTxt.height / 2); this.countdownTxt.addTo(this.fg); this.countdownTxt.position.set(640, 64); Thanks in advance! Quote Link to comment Share on other sites More sharing options...
enpu Posted July 10, 2018 Share Posted July 10, 2018 align property is used only on multi-line text, so you can remove that. To recenter you do have to set the x anchor after you change your text (because the width of the text changes), like this: this.countdownTxt.setText('9'); this.countdownTxt.anchor.x = this.countdownTxt.width / 2; Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted July 10, 2018 Author Share Posted July 10, 2018 @enpu Awesome, just tried it and it's working Thanks you for letting me know, I just thought I might be missing something. Quote Link to comment Share on other sites More sharing options...
luotuo Posted August 4, 2018 Share Posted August 4, 2018 On 7/10/2018 at 7:45 PM, enpu said: align property is used only on multi-line text, so you can remove that. To recenter you do have to set the x anchor after you change your text (because the width of the text changes), like this: this.countdownTxt.setText('9'); this.countdownTxt.anchor.x = this.countdownTxt.width / 2; thanks you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.