trueicecold Posted December 9, 2014 Report Share Posted December 9, 2014 Hey all Suppose I have a text calculated to be at the center the screen, when I change the text, obviously, the text isn't re-centered, since it was calculated with the old text.Is there a way of make the position persistent, regardless of the content inside, aside from recalculating it all the time inside the "render" event? This applies to groups with varying width/height children, text changes, sprite texture change etc... Thanks! Quote Link to comment Share on other sites More sharing options...
valueerror Posted December 10, 2014 Report Share Posted December 10, 2014 what if you set the x anchor of the text to 0.5?? Quote Link to comment Share on other sites More sharing options...
trueicecold Posted December 10, 2014 Author Report Share Posted December 10, 2014 valueerror, as far as I know anchoring doesn't work for text, unless I'm missing something? Quote Link to comment Share on other sites More sharing options...
gsko Posted December 10, 2014 Report Share Posted December 10, 2014 It works for Phaser.Text. I just did this about 10 minutes ago:var instructions = game.add.text(363, 20, msg, { fill: '#ffffff', font: "14px Arial", align: "center"});instructions.anchor.set(0.5,0);Centered the text for me. Where 363 is the width of my canvas/2. Original Solution Quote Link to comment Share on other sites More sharing options...
trueicecold Posted December 10, 2014 Author Report Share Posted December 10, 2014 gsko, now, when you resize the browser, does it keep anchoring itself? Quote Link to comment Share on other sites More sharing options...
gsko Posted December 10, 2014 Report Share Posted December 10, 2014 This is my first Phaser project and I have a set canvas size. So I don't know what would happen. Maybe someone more experienced has an idea. Quote Link to comment Share on other sites More sharing options...
valueerror Posted December 11, 2014 Report Share Posted December 11, 2014 just use something like game.width/2 instead for the x coordinate so it will be more flexible.. Quote Link to comment Share on other sites More sharing options...
trueicecold Posted December 11, 2014 Author Report Share Posted December 11, 2014 valueerror, yes, but that means I'll have to use it inside the "render" event to take care of resize events. I was wondering if there's a way to "bind" it so that I don't have to re-align elements when resizing. 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.