Skip to content

Assets API

Assets API Reference

Functions and classes for loading game assets.

Module Location

from assets.assets import (
getFont,
getMinecraftTexture,
get_texture_config,
get_platform_types,
get_texture_names,
Texture,
)

Functions

getFont(size)

Get a cached font at the specified size.

def getFont(size: int) -> pygame.font.Font

Parameters:

NameTypeDescription
sizeintFont size (1-99)

Returns: pygame.font.Font

Raises: RuntimeError if size < 0 or > 100

Example:

title_font = getFont(60)
small_font = getFont(16)
text = title_font.render("Hello", True, (255, 255, 255))

getMinecraftTexture(…)

Extract a texture region from the texture atlas.

def getMinecraftTexture(
location_x: int,
location_y: int,
width: int,
height: int,
top_left: Tuple[int, int] = (0, 0),
) -> pygame.Surface

Parameters:

NameTypeDefaultDescription
location_xint-X in atlas (pixels)
location_yint-Y in atlas (pixels)
widthint-Width to extract
heightint-Height to extract
top_lefttuple(0, 0)Output offset

Returns: pygame.Surface

Example:

# Extract 16x16 texture at position (352, 576)
grass = getMinecraftTexture(352, 576, 16, 16)

get_texture_config()

Load the full texture configuration from textures.json.

def get_texture_config() -> dict

Returns: Configuration dictionary with atlas, textures, and platform types.


get_platform_types()

Get the list of platform type names defined in textures.json.

def get_platform_types() -> List[str]

Example:

types = get_platform_types()
print(types) # ['NORMAL', 'DEATH', 'CHECKPOINT', ...]

get_texture_names()

Get the list of available texture names.

def get_texture_names() -> List[str]

Example:

names = get_texture_names()
print(names) # ['GRASS', 'ICE', 'STONE', ...]

Texture Class

Dynamically loaded textures from textures.json.

class Texture:
# Dynamically generated attributes
GRASS: pygame.Surface
STONE: pygame.Surface
ICE: pygame.Surface
LAVA: pygame.Surface
# ...and more from textures.json
@classmethod
def get(cls, name: str) -> Optional[pygame.Surface]: ...
@classmethod
def list_all(cls) -> List[str]: ...
@classmethod
def reload(cls) -> None: ...
@classmethod
def get_config(cls) -> dict: ...

Example:

from assets.assets import Texture
from skeletons.platform import Platform
platform = Platform(..., texture=Texture.GRASS)

Texture Helper Methods

Texture.get(name)

Get a texture by string name.

texture = Texture.get("GRASS")

Texture.list_all()

List all texture names loaded from config.

names = Texture.list_all()

Texture.reload()

Reload textures after editing textures.json.

Texture.reload()

Texture.get_config()

Return the raw textures dictionary from config.

config = Texture.get_config()

Adding Custom Textures

# In assets.py, add to Texture class:
class Texture:
# ... existing textures ...
MY_TEXTURE = getMinecraftTexture(x, y, 16, 16)

With dynamic textures, you can also add entries directly in textures.json without touching code. See Using Textures.