Crayon

AboutTutorialsDocumentationDemosDownloadSource

Graphics2DText

Provides functionality to render text in games made with the Game library

enum FontClass[link]

Used to identify a type of font class.

NameDescription
SERIF

SANS_SERIF

MONOSPACE

enum FontSourceType[link]

Used to identify the source of a font.

NameDescription
DEFAULT

RESOURCE

FILE

SYSTEM

enum FontStyle[link]

Used to identify a type of font style.

NameDescription
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

NameTypeDescription
text string

text to render

Return Value

TypeDescription
Graphics2DText.TextSurface

A surface containing pixel data.

function setColor(red, green, blue)[link]

Sets the color of the renderer.

Arguments

NameTypeDescription
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

TypeDescription
Graphics2DText.FontRenderer

Returns itself for chaining.

function setSize(size)[link]

Sets the font size of the renderer.

Arguments

NameTypeDescription
size integer

the new font size

Return Value

TypeDescription
Graphics2DText.FontRenderer

Returns itself for chaining.

function setStyle(style)[link]

Sets the style of the renderer (e.g. bold, italic)

Arguments

NameTypeDescription
style Graphics2DText.FontStyle

the new font style

Return Value

TypeDescription
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

NameTypeDescription
path string

file path to the font resource on disk

Return Value

TypeDescription
Graphics2DText.FontResource

A font resource

function fromResource(path)[link]

Loads a font face from an embedded resource.

Arguments

NameTypeDescription
path string

resource path of the font resource

Return Value

TypeDescription
Graphics2DText.FontResource

A font resource

function fromSystem(name)[link]

Loads a font face from a system-installed font.

Arguments

NameTypeDescription
name string

The name of the font resource.

Return Value

TypeDescription
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

NameTypeDescription
name string

The name of the font resource.

Return Value

TypeDescription
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

NameTypeDescription
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

NameTypeDescription
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).