pyxen.Text

Renders a text string on an Entity using a bitmap font.

Text entities use a font atlas for rendering — each character is drawn as a quad from the atlas texture.


Constructor

Text(
    content,
    *,
    font="_default",
    color=None,
    align="left"
)

Parameters

ParameterTypeDescription
contentstrThe text string to display
fontstrName of the font asset (default: built-in font)
color(r, g, b, a)Tint color (default: white)
alignstrText alignment: "left", "center", or "right"

content (Required)

The text string to render.

Text("Hello World")

font (Optional)

Name of the font asset to use. If omitted, the built-in default font is used.

Text("Score: 0", font="myfont")

A font asset consists of a .font.json descriptor and a .font.png atlas image.


color (Optional)

Tints the rendered text.

Text("Warning!", color=(1, 0, 0, 1))

Default: (1.0, 1.0, 1.0, 1.0) (white, fully opaque).


align (Optional)

Controls horizontal text alignment relative to the entity position.

Text("Centered", align="center")
ValueDescription
"left"Text starts at the entity position (default)
"center"Text is centered on the entity position
"right"Text ends at the entity position

Assigning Text

You can assign during spawn:

label = world.spawn(
    text=Text("Score: 0"),
    x=10, y=10, layer=200
)

Or later:

label.text = Text("Game Over", color=(1, 0, 0, 1))

Updating Text at Runtime

Access the text component through the entity to update properties:

label.text.content = "Score: 100"
label.text.color = (1, 1, 0, 1)
label.text.align = "center"

Removing Text

Set the text to None to remove it:

label.text = None

Example

from pyxen import *

score = 0

label = world.spawn(
    text=Text("Score: 0", color=(1, 1, 1, 1)),
    x=10, y=10, layer=200
)

def update():
    global score
    score += 1
    label.text.content = f"Score: {score}"