string_width_ext

Returns the maximum width in pixels of a string based on the given separation and line-break width.

Syntax:

GML Code Example

string_width_ext(string, sep, w);


Argument Description
string The string to measure the width of.
sep The distance in pixels between lines of text as if the string was being drawn.
w The maximum width (in pixels) of the string before a line break as if the string was bring drawn.


Returns: Real


Description

This function will return the maximum width (in pixels) of the input string, taking into account the line separation and line-break width (which is defined as the number of pixels that the string can occupy before a line break is inserted). It is very handy for calculating distances between text elements based on the maximum width of a string that is split over several lines as it would be drawn with draw_text_ext using the currently defined font. Separation and width can be set to -1 to get the default spacing.


Example:

GML Code Example

var ww;
 ww = string_width_ext(str_Story_Text[1], -1, 100);
 draw_text_ext(32, 32, str_Story_Text[1], -1, 100);
 draw_text_ext(32 + ww, 32, str_Story_Text[2], -1, 100);
 

The above code will get the width of the given string, taking into account the line separation and line-break width, and then draw two lines of text, using the returned total string width as a separator.


Back: Strings



No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here