Center text in rectangle?

0 views
Skip to first unread message

Thor

unread,
Oct 30, 2009, 9:49:38 PM10/30/09
to The Render Engine
Hi. I'm very new to the Render Engine - just finished the tutorial.
I'm looking to vertically and horizontally center an arbitrarily long
string in a Rectangle2D, and render it to the screen. I've been
looking into it for a while, and I haven't seemed to had any luck
figuring out how to do this. Any tips?

bfat...@gmail.com

unread,
Nov 7, 2009, 4:56:29 PM11/7/09
to The Render Engine
Hi Thor,

In the example, we're centering the text at the midpoint of the
playing field, which is a Rectangle2D. You could use the exact same
logic to position the text at the center of your own rectangle.

The line you're interested in is:

// Get the field center point
var fCenter = MyFirstGame.getFieldBox().getCenter();

If you need the text to move with the rectangle, you would add your
text object to the object which draws the rectangle.

- Brett
Reply all
Reply to author
Forward
0 new messages