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

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -