Graphics2DText
Provides functionality to render text in games made with the Game library
- namespace Graphics2DText
enum FontClass[link]
Used to identify a type of font class.
Name | Description |
---|---|
SERIF | |
SANS_SERIF | |
MONOSPACE |
enum FontSourceType[link]
Used to identify the source of a font.
Name | Description |
---|---|
DEFAULT | |
RESOURCE | |
FILE | |
SYSTEM |
enum FontStyle[link]
Used to identify a type of font style.
Name | Description |
---|---|
NORMAL | |
BOLD | |
ITALIC | |
BOLD_ITALIC |
class FontNotFoundException[link]
An exception thrown when a font cannot be found.
class FontRenderer[link]
Renders a specific font face, style, size, and color, by generating TextSurface instances.
function render(text)[link]
Renders text into a Graphics2DText.TextSurface instance, which can be used much like an ordinary Graphics2D.GraphicsTexture
Arguments
Name | Type | Description |
---|---|---|
text | string | text to render |
Return Value
Type | Description |
---|---|
Graphics2DText.TextSurface | A surface containing pixel data. |
function setColor(red, green, blue)[link]
Sets the color of the renderer.
Arguments
Name | Type | Description |
---|---|---|
red | integer | red component of the font color. |
green | integer | green component of the font color. |
blue | integer | blue component of the font color. |
Return Value
Type | Description |
---|---|
Graphics2DText.FontRenderer | Returns itself for chaining. |
function setSize(size)[link]
Sets the font size of the renderer.
Arguments
Name | Type | Description |
---|---|---|
size | integer | the new font size |
Return Value
Type | Description |
---|---|
Graphics2DText.FontRenderer | Returns itself for chaining. |
function setStyle(style)[link]
Sets the style of the renderer (e.g. bold, italic)
Arguments
Name | Type | Description |
---|---|---|
style | Graphics2DText.FontStyle | the new font style |
Return Value
Type | Description |
---|---|
Graphics2DText.FontRenderer | Returns itself for chaining. |
class FontResource[link]
Represents a font resource, regardless of where it came from. This can be used to generate new FontRenderer instances, which handle styling, color, etc.
function fromDisk(path)[link]
Loads a font face from an embedded resource.
Arguments
Name | Type | Description |
---|---|---|
path | string | file path to the font resource on disk |
Return Value
Type | Description |
---|---|
Graphics2DText.FontResource | A font resource |
function fromResource(path)[link]
Loads a font face from an embedded resource.
Arguments
Name | Type | Description |
---|---|---|
path | string | resource path of the font resource |
Return Value
Type | Description |
---|---|
Graphics2DText.FontResource | A font resource |
function fromSystem(name)[link]
Loads a font face from a system-installed font.
Arguments
Name | Type | Description |
---|---|---|
name | string | The name of the font resource. |
Return Value
Type | Description |
---|---|
Graphics2DText.FontResource | A font resource |
function getRenderer()[link]
Get a render instance for this font face.
function isSystemFontPresent(name)[link]
Determines if the given font is present on the current system.
Arguments
Name | Type | Description |
---|---|---|
name | string | The name of the font resource. |
Return Value
Type | Description |
---|---|
boolean | True if that font is present. |
class TextSurface[link]
A surface containing some rendered text. These are generated from the Graphics2DText.FontRenderer's render method.
function draw(x, y)[link]
Renders a text surface to the screen at the given coordinates. These coordinates describe the position of the top left corner of the text surface on the screen.
Arguments
Name | Type | Description |
---|---|---|
x | integer | X coordinate to draw this text surface to |
y | integer | Y coordinate to draw this text surface to |
function drawWithAlpha(x, y, alpha)[link]
Renders a text surface to the screen at the given coordinates. These coordinates describe the position of the top left corner of the text surface on the screen. The surface will be drawn at the given opacity.
Arguments
Name | Type | Description |
---|---|---|
x | integer | X coordinate to draw this text surface to |
y | integer | Y coordinate to draw this text surface to |
alpha | integer | Alpha value to draw this surface with (0-255). |