Difference between revisions of "love.graphics.printf"

(Updated for 11.0)
(6 new variants and make argument name consistent)
Line 42: Line 42:
 
{{param|number|kx (0)|Shearing factor (x-axis).}}
 
{{param|number|kx (0)|Shearing factor (x-axis).}}
 
{{param|number|ky (0)|Shearing factor (y-axis).}}
 
{{param|number|ky (0)|Shearing factor (y-axis).}}
 +
=== Returns ===
 +
Nothing.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( text, font, x, y, limit, align, r, sx, sy, ox, oy, kx, ky )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|text|A text string.}}
 +
{{param|Font|font|The Font object to use.}}
 +
{{param|number|x|The position on the x-axis.}}
 +
{{param|number|y|The position on the y-axis.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 +
{{param|number|r (0)|Orientation (radians).}}
 +
{{param|number|sx (1)|Scale factor (x-axis).}}
 +
{{param|number|sy (sx)|Scale factor (y-axis).}}
 +
{{param|number|ox (0)|Origin offset (x-axis).}}
 +
{{param|number|oy (0)|Origin offset (y-axis).}}
 +
{{param|number|kx (0)|Shearing factor (x-axis).}}
 +
{{param|number|ky (0)|Shearing factor (y-axis).}}
 +
=== Returns ===
 +
Nothing.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( text, transform, limit, align )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|text|A text string.}}
 +
{{param|Transform|transform|Transformation object.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 +
=== Returns ===
 +
Nothing.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( text, font, transform, limit, align )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|text|A text string.}}
 +
{{param|Font|font|The Font object to use.}}
 +
{{param|Transform|transform|Transformation object.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 49: Line 101:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.graphics.printf( coloredtext, x, y, wraplimit, alignmode, angle, sx, sy, ox, oy, kx, ky )
+
love.graphics.printf( coloredtext, x, y, limit, align, angle, sx, sy, ox, oy, kx, ky )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
Line 60: Line 112:
 
{{param|number|x|The position of the text (x-axis).}}
 
{{param|number|x|The position of the text (x-axis).}}
 
{{param|number|y|The position of the text (y-axis).}}
 
{{param|number|y|The position of the text (y-axis).}}
{{param|number|wraplimit|The maximum width in pixels of the text before it gets automatically wrapped to a new line.}}
+
{{param|number|limit|The maximum width in pixels of the text before it gets automatically wrapped to a new line.}}
 
{{param|AlignMode|align|The alignment of the text.}}
 
{{param|AlignMode|align|The alignment of the text.}}
 
{{param|number|angle (0)|Orientation (radians).}}
 
{{param|number|angle (0)|Orientation (radians).}}
Line 69: Line 121:
 
{{param|number|kx (0)|Shearing / skew factor (x-axis).}}
 
{{param|number|kx (0)|Shearing / skew factor (x-axis).}}
 
{{param|number|ky (0)|Shearing / skew factor (y-axis).}}
 
{{param|number|ky (0)|Shearing / skew factor (y-axis).}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
The color set by [[love.graphics.setColor]] will be combined (multiplied) with the colors of the text.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( coloredtext, font, x, y, limit, align, angle, sx, sy, ox, oy, kx, ky )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|coloredtext|A table containing colors and strings to add to the object, in the form of <code>{color1, string1, color2, string2, ...}</code>.}}
 +
{{subparam|table|color1|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string1|A string of text which has a color specified by the previous color.}}
 +
{{subparam|table|color2|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string2|A string of text which has a color specified by the previous color.}}
 +
{{subparam|tables and strings|...|Additional colors and strings.}}
 +
{{param|Font|font|The Font object to use.}}
 +
{{param|number|x|The position on the x-axis.}}
 +
{{param|number|y|The position on the y-axis.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 +
{{param|number|angle (0)|Orientation (radians).}}
 +
{{param|number|sx (1)|Scale factor (x-axis).}}
 +
{{param|number|sy (sx)|Scale factor (y-axis).}}
 +
{{param|number|ox (0)|Origin offset (x-axis).}}
 +
{{param|number|oy (0)|Origin offset (y-axis).}}
 +
{{param|number|kx (0)|Shearing factor (x-axis).}}
 +
{{param|number|ky (0)|Shearing factor (y-axis).}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
The color set by [[love.graphics.setColor]] will be combined (multiplied) with the colors of the text.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( coloredtext, transform, limit, align )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|coloredtext|A table containing colors and strings to add to the object, in the form of <code>{color1, string1, color2, string2, ...}</code>.}}
 +
{{subparam|table|color1|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string1|A string of text which has a color specified by the previous color.}}
 +
{{subparam|table|color2|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string2|A string of text which has a color specified by the previous color.}}
 +
{{subparam|tables and strings|...|Additional colors and strings.}}
 +
{{param|Transform|transform|Transformation object.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 +
=== Returns ===
 +
Nothing.
 +
=== Notes ===
 +
The color set by [[love.graphics.setColor]] will be combined (multiplied) with the colors of the text.
 +
 +
== Function ==
 +
{{newin|[[11.0]]|110|type=variant}}
 +
=== Synopsis ===
 +
<source lang="lua">
 +
love.graphics.printf( coloredtext, font, transform, limit, align )
 +
</source>
 +
=== Arguments ===
 +
{{param|table|coloredtext|A table containing colors and strings to add to the object, in the form of <code>{color1, string1, color2, string2, ...}</code>.}}
 +
{{subparam|table|color1|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string1|A string of text which has a color specified by the previous color.}}
 +
{{subparam|table|color2|A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of <code>{red, green, blue, alpha}</code>.}}
 +
{{subparam|string|string2|A string of text which has a color specified by the previous color.}}
 +
{{subparam|tables and strings|...|Additional colors and strings.}}
 +
{{param|Font|font|The Font object to use.}}
 +
{{param|Transform|transform|Transformation object.}}
 +
{{param|number|limit|Wrap the line after this many horizontal pixels.}}
 +
{{param|AlignMode|align ("left")|The alignment.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.

Revision as of 12:58, 19 February 2019

Draws formatted text, with word wrap and alignment.

See additional notes in love.graphics.print.

In version 0.9.2 and earlier, wrapping was implemented by breaking up words by spaces and putting them back together to make sure things fit nicely within the limit provided. However, due to the way this is done, extra spaces between words would end up missing when printed on the screen, and some lines could overflow past the provided wrap limit. In version 0.10.0 and newer this is no longer the case.

In versions prior to 11.0, color and byte component values were within the range of 0 to 255 instead of 0 to 1.

O.png Aligning does not work as one might expect! It doesn't align to the x/y coordinates given, but in a rectangle, where the limit is the width.  


O.png Text may appear blurry if it's rendered at non-integer pixel locations.  


Function

Synopsis

love.graphics.printf( text, x, y, limit, align )

Arguments

string text
A text string.
number x
The position on the x-axis.
number y
The position on the y-axis.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.

Returns

Nothing.

Function

Available since LÖVE 0.9.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( text, x, y, limit, align, r, sx, sy, ox, oy, kx, ky )

Arguments

string text
A text string.
number x
The position on the x-axis.
number y
The position on the y-axis.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.
number r (0)
Orientation (radians).
number sx (1)
Scale factor (x-axis).
number sy (sx)
Scale factor (y-axis).
number ox (0)
Origin offset (x-axis).
number oy (0)
Origin offset (y-axis).
number kx (0)
Shearing factor (x-axis).
number ky (0)
Shearing factor (y-axis).

Returns

Nothing.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( text, font, x, y, limit, align, r, sx, sy, ox, oy, kx, ky )

Arguments

string text
A text string.
Font font
The Font object to use.
number x
The position on the x-axis.
number y
The position on the y-axis.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.
number r (0)
Orientation (radians).
number sx (1)
Scale factor (x-axis).
number sy (sx)
Scale factor (y-axis).
number ox (0)
Origin offset (x-axis).
number oy (0)
Origin offset (y-axis).
number kx (0)
Shearing factor (x-axis).
number ky (0)
Shearing factor (y-axis).

Returns

Nothing.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( text, transform, limit, align )

Arguments

string text
A text string.
Transform transform
Transformation object.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.

Returns

Nothing.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( text, font, transform, limit, align )

Arguments

string text
A text string.
Font font
The Font object to use.
Transform transform
Transformation object.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.

Returns

Nothing.

Function

Available since LÖVE 0.10.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( coloredtext, x, y, limit, align, angle, sx, sy, ox, oy, kx, ky )

Arguments

table coloredtext
A table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
table color1
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string1
A string of text which has a color specified by the previous color.
table color2
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string2
A string of text which has a color specified by the previous color.
tables and strings ...
Additional colors and strings.
number x
The position of the text (x-axis).
number y
The position of the text (y-axis).
number limit
The maximum width in pixels of the text before it gets automatically wrapped to a new line.
AlignMode align
The alignment of the text.
number angle (0)
Orientation (radians).
number sx (1)
Scale factor (x-axis).
number sy (sx)
Scale factor (y-axis).
number ox (0)
Origin offset (x-axis).
number oy (0)
Origin offset (y-axis).
number kx (0)
Shearing / skew factor (x-axis).
number ky (0)
Shearing / skew factor (y-axis).

Returns

Nothing.

Notes

The color set by love.graphics.setColor will be combined (multiplied) with the colors of the text.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( coloredtext, font, x, y, limit, align, angle, sx, sy, ox, oy, kx, ky )

Arguments

table coloredtext
A table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
table color1
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string1
A string of text which has a color specified by the previous color.
table color2
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string2
A string of text which has a color specified by the previous color.
tables and strings ...
Additional colors and strings.
Font font
The Font object to use.
number x
The position on the x-axis.
number y
The position on the y-axis.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.
number angle (0)
Orientation (radians).
number sx (1)
Scale factor (x-axis).
number sy (sx)
Scale factor (y-axis).
number ox (0)
Origin offset (x-axis).
number oy (0)
Origin offset (y-axis).
number kx (0)
Shearing factor (x-axis).
number ky (0)
Shearing factor (y-axis).

Returns

Nothing.

Notes

The color set by love.graphics.setColor will be combined (multiplied) with the colors of the text.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( coloredtext, transform, limit, align )

Arguments

table coloredtext
A table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
table color1
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string1
A string of text which has a color specified by the previous color.
table color2
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string2
A string of text which has a color specified by the previous color.
tables and strings ...
Additional colors and strings.
Transform transform
Transformation object.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.

Returns

Nothing.

Notes

The color set by love.graphics.setColor will be combined (multiplied) with the colors of the text.

Function

Available since LÖVE 11.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.printf( coloredtext, font, transform, limit, align )

Arguments

table coloredtext
A table containing colors and strings to add to the object, in the form of {color1, string1, color2, string2, ...}.
table color1
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string1
A string of text which has a color specified by the previous color.
table color2
A table containing red, green, blue, and optional alpha components to use as a color for the next string in the table, in the form of {red, green, blue, alpha}.
string string2
A string of text which has a color specified by the previous color.
tables and strings ...
Additional colors and strings.
Font font
The Font object to use.
Transform transform
Transformation object.
number limit
Wrap the line after this many horizontal pixels.
AlignMode align ("left")
The alignment.

Returns

Nothing.

Notes

The color set by love.graphics.setColor will be combined (multiplied) with the colors of the text.

Examples

Draw text to the screen with right alignment and a horizontal limit of 125.

love.graphics.printf("This text is aligned right, and wraps when it gets too big.", 25, 25, 125, "right")

Notes

Note that the limit argument affects the position of your text for 'center' and 'right' alignment.

love.graphics.printf("This text is aligned center",100, 100, 200,"center") -- center your text around x = 200/2 + 100 = 200
love.graphics.printf("This text is aligned right",100, 100, 200,"right") -- align right to x = 100 + 200 = 300

See Also



Other Languages