Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Direction in Phaser.js

I would like to know if there is any text direction on Phaser.js Text class like when user input some text, then the text input in the canvas will have a text direction of right to left or left to right;

and I'm implementing this on whole canvas application

example in the normal html we can attain this using the css properties

 direction:ltr,

   direction:rtl

anyone has any idea on how to do it.

i was reading on the phaser.js text class but cannot find any properties to set the direction to right to left but no luck.

thanks in advance;

like image 556
Oli Soproni B. Avatar asked Mar 03 '15 05:03

Oli Soproni B.


1 Answers

Since I can't find any documentation on the phaser to make this happen then i simply just make a work around to look like i am able to make the direction of the text to be right align.

Here is a simple text

var txt = this.game.add.text(10, 10, '0', {
    font: "21px arial", 
    fill: "#00FF00", 
    align:'right', 
    fontWeight:'bold',
});

compute for the new position x of the txt

formula :

txt.x = contant - txt.width

the constant will be a reference point you want to offset according to your positioning

so when the variable txt text updated

then you can re-position it again using the the new data

txt.setText(100);

txt.x = 84 - (txt.width);
like image 141
Oli Soproni B. Avatar answered Oct 05 '22 23:10

Oli Soproni B.