Jump to content

How to scale text?


Joss
 Share

Recommended Posts

Been trying to use 'text.scale = ' to make my text bigger as the screen gets bigger, and although it seems to work, it stop the x,y positioning of the text from working

 

                         text.setText("GAME OVER\n" + "Score : " + score);
                         text.position.x = 100*scaleFactor;
                         text.position.y = 160*scaleFactor;

                         text.setStyle({font:"30px Arial", fill:"red", align:"center"});

 

                        if i add

 

                        text.scale = scaleFactor; then the text just ends up in the top left corner

 

                        Am I doing something wrong?

 

Thanks

 

Joss

Link to comment
Share on other sites

Hope it's ok to hijack this thread to ask another question about text rather than create an new one. :)

 

I've been trying to center my text within my screen dynamically. To do this I need the width of the text.

text.width always gives 300 no matter what my text is. text.texture.frame.width gives something which looks accurate but it seems to take a frame to update, meaning it's annoying to use. Is there a way around this - to create some text and immediately get it's size?

 

Edit: Actually it turns out text.width is correct, but just it doesn't update immediately and my console.log was reading it from the wrong point.

Link to comment
Share on other sites

HappinessSam, the canvas context has a measureText function that can calculate the width of any text based on the context font and size. Just in case you might need it.

 

Edit: oh sorry, this is the pixi.js forum, thought it was a general canvas question

Link to comment
Share on other sites

  • 4 months later...

Hope it's ok to hijack this thread to ask another question about text rather than create an new one. :)

 

I've been trying to center my text within my screen dynamically. To do this I need the width of the text.

text.width always gives 300 no matter what my text is. text.texture.frame.width gives something which looks accurate but it seems to take a frame to update, meaning it's annoying to use. Is there a way around this - to create some text and immediately get it's size?

 

Edit: Actually it turns out text.width is correct, but just it doesn't update immediately and my console.log was reading it from the wrong point.

 

HappinessSam, I am running into the same issues.  Alignment is a bear.  When I read the width of the text right after I draw it (it is already added to the stage too) it always reads the same, no matter how it is scaled.  Did you see this issue as well?  If so, what did you do about it?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...