Skip to main content

Assets and Rendering

AssetEntry

FieldTypeMeaning
bankuint8_tROM bank containing the asset data.
datauint8_t*Asset data in that bank.

Animation.h

Header: core/src/Assets/Animations/Animation.h

Animation

FieldTypeMeaning
number_of_framesuint8_tNumber of frames in the animation.
width, heightuint8_tSprite dimensions in pixels.
frame_durationuint8_tTicks per frame before advancing.
animation_iduint8_tIndex into generated animation registries.
metaspritemetasprite_t*Layout for multi-sprite animations.

AnimationState

Each actor with an active animation owns an AnimationState. The Animation describes the shared asset, while AnimationState stores the playback and rendering state for that particular actor.

FieldTypeMeaning
speed_modifieruint8_tAmount added to the animation timer on each update. It defaults to 1; 0 pauses frame advancement.
current_frameuint8_tZero-based frame currently being displayed.
sprite_slotuint8_tFirst hardware sprite slot allocated to this animation instance.
propsuint8_tCurrent Game Boy sprite properties, including palette, priority, and flip flags.
time_since_last_frameuint8_tAccumulated animation ticks since the last frame change.

The engine allocates and initializes this state when set_actor_animation() selects an animation, and releases it when that animation is removed or replaced. Game code can adjust fields such as speed_modifier, but it should not change sprite_slot because the animation system owns that allocation.

Animation context

The low-level animation functions operate on the global THIS_ANIMATION and THIS_ANIMATION_STATE pointers. set_animation_context() copies the current THIS_ACTOR->current_animation and THIS_ACTOR->animation_state into those pointers.

Call set_animation_context() after selecting the target through THIS_ACTOR and before directly calling any function that uses the current animation context:

  • load_animation()
  • unload_animation()
  • set_animation_props()
  • move_animation()
  • update_animation()
  • hide_animation()

In normal game code, load_animation() and unload_animation() should remain managed by set_actor_animation(). The most common direct use is changing properties:

THIS_ACTOR = actor;
set_animation_context();
set_animation_props(S_FLIPX, sprite_x, sprite_y);

Set the context again whenever THIS_ACTOR changes before another direct animation call. The context is global and remains pointed at the last selected actor; restoring THIS_ACTOR by itself does not restore THIS_ANIMATION or THIS_ANIMATION_STATE.

You do not need to call set_animation_context():

  • Before set_actor_animation(), because that function manages the context needed to load or unload an animation.
  • For normal scene rendering through the actor draw loop, because draw() sets the context before updating the animation.
  • When using actor movement, positioning, tags, or collision functions that do not call the low-level animation API.
  • Before init_animation_state(state), because it receives the state pointer explicitly.

If you call a low-level animation function immediately after set_actor_animation(), still set the context explicitly. set_actor_animation() returns early when the requested animation is already active, so relying on its internal context changes can target the wrong actor.

Animation properties

set_animation_props(props, x, y) stores the properties in the current AnimationState and redraws the current frame at x, y. It requires the animation context described above.

The same property flags apply to single-sprite and metasprite animations. For metasprites, S_FLIPX and S_FLIPY mirror the complete metasprite layout around its pivot as well as flipping its component sprites; the remaining flags keep their normal base-property behavior.

AnimationRegistry.h

Header: core/src/Assets/Animations/AnimationRegistry.h

AnimationType

Default value in the shipped core:

  • NUMBER_OF_ANIMATIONS = 1

Globals

NameTypeMeaning
animationsconst Animation* [NUMBER_OF_ANIMATIONS]Generated animation list.
animation_dataconst AssetEntry [NUMBER_OF_ANIMATIONS]Generated animation tile data.

Map.h

Header: core/src/Assets/Map/Map.h

Constants

NameValueMeaning
TILE_SIZE_BYTES16Bytes per Game Boy tile.
MAX_CHANGED_MAP_TILES32 by defaultMaximum tile overrides. Define this before including Map.h to use a different limit.

Map

FieldTypeMeaning
iduint8_tIndex into generated map registries.
width, heightuint16_tMap dimensions in tiles.
tilesetuint8_t*Tile graphics data.
num_tilesuint8_tNumber of tiles in the tileset.
first_tileuint8_tFirst allocated tile slot in VRAM.

Functions

FunctionDescription
uint8_t register_changed_map_tile(uint8_t x, uint8_t y, uint8_t tile) BANKED;Stores a replacement for one background tile. Returns nonzero on success.
uint8_t change_changed_map_tile(uint8_t x, uint8_t y, uint8_t tile) BANKED;Updates an existing tile override. Returns nonzero when an override existed at that coordinate.
uint8_t delete_changed_map_tile(uint8_t x, uint8_t y) BANKED;Removes an existing tile override and redraws the original background tile when it is visible. Returns nonzero when an override existed.
void clear_changed_map_tiles(void) BANKED;Removes all tile overrides and redraws the visible map area.

Behavior notes

  • Changed map tiles use tile coordinates, not pixels. They affect background drawing only.
  • Registered changes are applied immediately if the tile is visible.
  • Registered changes are reapplied when background sections are redrawn, including during camera movement.
  • Registering a duplicate coordinate or exceeding MAX_CHANGED_MAP_TILES returns 0. Use change_changed_map_tile() to update an existing override.
  • Replacing the scene background map clears the changed-tile list.

MapRegistry.h

Header: core/src/Assets/Map/MapRegistry.h

MapType

Default value in the shipped core:

  • NUMBER_OF_MAPS = 1

Globals

NameTypeMeaning
mapsMap* [NUMBER_OF_MAPS]Generated map list.
map_dataconst AssetEntry [NUMBER_OF_MAPS]Generated map tile data.

Camera.h

Header: core/src/Camera/Camera.h

Globals

NameTypeMeaning
camera_x, camera_yuint16_tCamera position in pixels.
deadzone_left, deadzone_rightuint8_tHorizontal follow deadzone margins.
deadzone_top, deadzone_bottomuint8_tVertical follow deadzone margins.

Behavior notes

  • Camera movement streams only the newly visible tile row or column.
  • Configure camera deadzones on the actor that has Follow camera enabled in the scene editor. The actor properties expose Left, Right, Top, and Bottom deadzone margins in pixels. Generated scene initialization writes those values into deadzone_left, deadzone_right, deadzone_top, and deadzone_bottom before marking the actor as followed, and the scene viewport preview uses the same values when drawing the screen outline.
  • If no custom values are set, each deadzone margin defaults to 20 pixels.