mvbg

VM_SET_SPRITE_MODE

VM_SET_SPRITE_MODE is a GBVM instruction used to configure the Game Boy’s sprite rendering mode, specifically determining whether sprites are treated as 8x8 pixels or 8x16 pixels.

Purpose: On the Game Boy, sprites are typically composed of 8x8 pixel tiles. However, the hardware also supports a mode where two 8x8 tiles are combined vertically to form an 8x16 pixel sprite. VM_SET_SPRITE_MODE is essential for:

When VM_SET_SPRITE_MODE is called, it changes a global setting for how the Game Boy’s PPU (Picture Processing Unit) interprets sprite data. All subsequent sprites drawn will adhere to the newly set mode until it is changed again.

Syntax:

VM_SET_SPRITE_MODE MODE

Usage Example: Switching Sprite Mode for a Boss Battle

Imagine your game has a large boss character that requires more detail than regular enemies. You can switch the sprite mode to 8x16 when the boss battle begins, allowing the boss to be rendered with larger sprites, and then switch back to 8x8 after the battle.

; In your script, when a boss battle begins:

; Define sprite mode constants
.MODE_8X8:
  .R_INT8 0 ; Example value for 8x8 mode
.MODE_8X16:
  .R_INT8 1 ; Example value for 8x16 mode

START_BOSS_BATTLE:
  ; Set sprite mode to 8x16 for the large boss character
  VM_SET_SPRITE_MODE .MODE_8X16

  ; Load boss spritesheet (designed for 8x16 sprites)
  VM_ACTOR_SET_SPRITESHEET BOSS_ACTOR_ID, SHEET_BOSS_BANK, SHEET_BOSS

  ; Position the boss
  VM_ACTOR_SET_POS BOSS_ACTOR_ID, BOSS_START_X, BOSS_START_Y

  VM_LOAD_TEXT TEXT_BOSS_APPEARS
  VM_DISPLAY_TEXT
  VM_IDLE 60

  ; ... boss battle logic ...

END_BOSS_BATTLE:
  ; After the boss is defeated, switch sprite mode back to 8x8
  VM_SET_SPRITE_MODE .MODE_8X8

  ; You might also unload boss sprites and load regular enemy sprites
  ; VM_ACTOR_DEACTIVATE BOSS_ACTOR_ID

  VM_LOAD_TEXT TEXT_BOSS_DEFEATED
  VM_DISPLAY_TEXT
  VM_IDLE 60

  VM_RET

TEXT_BOSS_APPEARS:
  .TEXT "A giant foe appears!"
  .TEXT_END

TEXT_BOSS_DEFEATED:
  .TEXT "The boss is defeated!"
  .TEXT_END

BOSS_ACTOR_ID:
  .R_INT8 100 ; Example Actor ID for the boss
SHEET_BOSS_BANK:
  .R_INT8 BANK(SHEET_BOSS)
SHEET_BOSS:
  ; ... raw sprite data for boss (designed for 8x16) ...

In this example, VM_SET_SPRITE_MODE .MODE_8X16 is called at the beginning of the boss battle. This tells the Game Boy to interpret all sprite data as 8x16 pixel sprites, allowing the boss character to be rendered larger and with more detail. After the battle, the mode is switched back to 8x8, which is typically the default for most other game elements.

Analogy to other programming concepts: This is analogous to changing a global rendering setting or a graphics pipeline configuration in a game engine. For example, in a 3D engine, it might be like switching between different rendering passes or shader configurations that affect how all objects are drawn. On the Game Boy, it’s a fundamental hardware setting that impacts how all sprites are displayed, affecting their size and how VRAM is utilized for them.