Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

gba::object Reference

gba::object is the regular (non-affine) OAM object entry type from <gba/video>.

Use it with gba::obj_mem when you want standard sprite placement with optional horizontal/vertical flipping.

For affine objects, see gba::object_affine.

Include

#include <gba/video>

Type summary

struct object {
    // Attribute 0
    unsigned short y : 8;
    bool : 1;
    bool disable : 1;
    gba::mode mode : 2;
    bool mosaic : 1;
    gba::depth depth : 1;
    gba::shape shape : 2;

    // Attribute 1
    unsigned short x : 9;
    short : 3;
    bool flip_x : 1;
    bool flip_y : 1;
    unsigned short size : 2;

    // Attribute 2
    unsigned short tile_index : 10;
    unsigned short background : 2;
    unsigned short palette_index : 4;
};

sizeof(gba::object) == 6 bytes.

Typical usage

gba::obj_mem[0] = {
    .y = 80,
    .x = 120,
    .shape = gba::shape_square,
    .size = 1,          // 16x16 for square sprites
    .depth = gba::depth_4bpp,
    .tile_index = 0,
    .palette_index = 0,
};

Field notes

  • disable: hide this object without clearing its other fields.
  • mode: object blend/window mode (mode_normal, mode_blend, mode_window).
  • depth: choose depth_4bpp (16-colour banked palette) or depth_8bpp (256-colour OBJ palette).
  • shape + size: together determine dimensions.
  • flip_x/flip_y: valid for regular objects.
  • background: OBJ priority relative to backgrounds (0 highest, 3 lowest).

Regular vs affine comparison

Aspectgba::object (regular)gba::object_affine
Typed OAM viewgba::obj_memgba::obj_aff_mem
Attr0 mode bitdisable hide flagaffine enabled, optional double_size
Attr1 control bitsflip_x / flip_yaffine_index (0..31)
Rotation/scalingNot supportedSupported via affine matrix
Transform sourceFlip bits onlymem_obj_affa/b/c/d entry selected by affine_index
Shared fieldsx, y, shape, size, tile_index, background, palette_index, depth, mode, mosaicSame shared fields
Best fitStandard sprites, mirroring, UI, low overheadRotating/scaling sprites, camera-facing effects

Shape/size table

ShapeSize 0Size 1Size 2Size 3
Square8x816x1632x3264x64
Wide16x832x832x1664x32
Tall8x168x3216x3232x64
  • gba::obj_mem - typed OAM as object[128]
  • gba::tile_index(ptr) - compute OBJ tile index from an OBJ VRAM pointer
  • gba::mem_vram_obj - raw object VRAM