Drawing Text
Creating Strings
Drawing text to the screen with Amphora requires two things: a font loaded using resources.h
, and an AmphoraString
struct.
The first thing you'll want to do is create a new AmphoraString *
set to NULL
:
The AmphoraString
pointer will be used with the Amphora_CreateString
function which has the following signature:
Creating an AmphoraString
with Amphora_CreateString
will automatically add that string to the render list to be displayed.
Description of parameters
The
font_name
parameter is the string name of the font to be used for the string. This is the name specified inresources.h
. In the case of the exampleresources.h
, this could be"Roboto"
.The
pt
parameter is the font size.The
x
andy
parameters control the position on screen of the string. Ifstationary
(explained later on this page) is set to false, these parameters are the absolute coordinates of the string and so will visually move as the camera moves. Ifstationary
is set to true, these parameters are the distance from the window edges of the string, and the string will always be at the same location on screen regardless of where the camera is. Withstationary
set to true, positivex
andy
values will count from the left and top edges of the window to the string, and negativex
andy
values will count from the right and bottom edges of the window to the string.The
order
parameter controls the draw order and applied to strings and sprites. Higher numbers will be drawn on top of lower numbers.The
color
parameter is the color of the text. This can be anySDL_Color
, but is most commonly a color defined incolors.h
.The
stationary
parameter determines whether the string is stationary or not. A stationary string will always be displayed at the same screen location no matter where the camera is. This is commonly used for things like a score display or a timer, or text within a dialog box. A non-stationary string is fixed to an actual coordinate in the game world, and would be commonly used for textual elements in the game environment (think billboards, signs, etc.).The
fmt
parameter and following is the actual text to be drawn as a format string.
Updating String Text
You can change the text of an AmphoraString
using the Amphora_UpdateStringText
function:
This will overwrite the old text with the new format string provided.
Changing the Number of Characters Displayed
You can change how many characters of a string are displayed with the Amphora_UpdateStringCharsDisplayed
function:
This will display only the first 'n' characters of the string. Passing 0 for n
will cause the entire string to be displayed. This can be used to create a typewriter effect by incrementing the value passed as n over time.
Freeing Strings
Freeing an AmphoraString
when you no longer need it is accomplished with the Amphora_FreeString
function which has the following signature:
In our example, the call would be as follows:
The Amphora_FreeString
function automatically sets the AmphoraString
pointer back to a null pointer for you after freeing the resources.
It is only necessary to call Amphora_FreeString
on any strings you no longer want to be displayed, Amphora will automatically call Amphora_FreeString
on any remaining strings as part of its shutdown routine.