ScaleX
Introduction
The ScaleX and ScaleY properties are read-only properties in the Text class. You may be familiar with these properties through classes such as Sprite or AxisAlignedRectangle. Unlike those classes, the Text class's ScaleX and ScaleY properties are only used to read the dimensions of the Text object, not to set it. To set the size of your Text, you need to use the Scale, Spacing, and NewlineDistance properties. You can find out more about them here.
Scale and Position
If you've read about the IScalable interface, then you're likely familiar with the concept of Scale. To help you remember, Scale is the measure from the center of an object to its edge. Another way to put it is ScaleX is half of an object's width and ScaleY is half of an object's height. In most cases, the center of an object is the same as its Position. Therefore, adding or subtracting Scale from an object's position will give you its edges. This is not the case with Text objects because of the HorizontalAlignment and VerticalAlignment properties. Therefore, to find the center of your Text object, you should use the HorizontalCenter and VerticalCenter properties.
Code example
The following code creates two Text objects. It then creates two AxisAlignedRectangles which show the bounds of the Text object using ScaleX/ScaleY and HorizontalCenter/VerticalCenter properties. Add the following include statements:
Add the following to the Initialize method after initializing FlatRedBallServices:
Last updated