Joss Posted May 21, 2013 Share Posted May 21, 2013 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 Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted May 21, 2013 Share Posted May 21, 2013 hello! this should do the trick... replace:text.scale = scaleFactor; with:text.scale.x = scaleFactor;text.scale.y = scaleFactor; cheers! Mat RussiSunni 1 Quote Link to comment Share on other sites More sharing options...
HappinessSam Posted May 22, 2013 Share Posted May 22, 2013 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. Quote Link to comment Share on other sites More sharing options...
Joss Posted May 22, 2013 Author Share Posted May 22, 2013 Thanks Mat, that worked perfectly! Quote Link to comment Share on other sites More sharing options...
whirlibulf Posted May 22, 2013 Share Posted May 22, 2013 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 Quote Link to comment Share on other sites More sharing options...
mwatt Posted October 15, 2013 Share Posted October 15, 2013 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? 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.