Legacy:Font/getStringWidth
From Spherical
Get the pixel width of a string if it were drawn with Font.drawText().
Contents
Usage
integer Font.getStringWidth(text);
- text string. The text to measure the pixel width of
Examples
This will write a simple string that is centered on the screen.
function game()
{
var message = "Hi everybody! Press a key to end.";
var font = GetSystemFont();
var height = font.getHeight();
var width = font.getStringWidth(message);
var x = GetScreenWidth() - Math.floor(width / 2);
var y = GetScreenHeight() - Math.floor(height / 2);
// clear the key queue
while (AreKeysLeft())
GetKey();
// blit the text until a key is pressed
while (!AreKeysLeft())
{
font.drawText(x, y, message);
FlipScreen();
}
}
See also
- Sphere Font object
- Font.drawText()
- Font.getHeight()
- Font.getStringHeight()
- AreKeysLeft()
- FlipScreen()
- GetKey()
- GetScreenHeight()
- GetScreenWidth()
- GetSystemFont()