javascript - How to centrally align text in HTML canvas? -


i making small javascript game when ran small issue: text not centrally aligned. simple example:

var txt="lorem ipsum"; context.filltext(txt,100,100); 

now problem beginning of text @ point 100,100. later when change value of txt longer sentence, still drawn staring 100,100 , reducing aesthetic appeal of program.

my question is, there way draw text in such way coordinates given mark center of text , not beginning?

you can use textalign:

context.textalign = "center"; 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -