Built-in Functions

All built-ins are imported from the core module:

from core import pressed, just_pressed, set_sprite, set_bg_tile, set_scroll, Button

Input

pressed(button) -> bool

Returns true if the button is currently held down.

if pressed(Button.Right):
    x := x + 1

just_pressed(button) -> bool

Returns true only on the first frame the button is pressed. Useful for actions that should trigger once (like jumping).

if just_pressed(Button.A):
    vy := -8

Button enum

ValueGame Boy button
Button.UpD-pad up
Button.DownD-pad down
Button.LeftD-pad left
Button.RightD-pad right
Button.AA button
Button.BB button
Button.StartStart
Button.SelectSelect

Sprites

set_sprite(index, x, y, tile)

Places a sprite on screen.

ParamTypeDescription
indexu8Sprite slot (0โ€“39)
xu8X position in pixels
yu8Y position in pixels
tiletile nameWhich tile graphic to use
set_sprite(0, 80, 72, player)

The Game Boy can display up to 40 sprites, with a limit of 10 per scanline. Sprite coordinates place the top-left corner of the 8ร—8 tile at (x, y). A sprite at (0, 0) is at the top-left of the screen.


Background

set_bg_tile(tx, ty, tile)

Places a tile on the background layer.

ParamTypeDescription
txu8Tile column (0โ€“31)
tyu8Tile row (0โ€“31)
tiletile nameWhich tile graphic to draw
# Fill row 16 with ground tiles
let i = 0
while i < 20:
    set_bg_tile(i, 16, ground)
    i := i + 1

The background is a 32ร—32 grid of 8ร—8 tiles. The visible screen shows a 20ร—18 window into this grid (160ร—144 pixels). Use set_scroll to pan the view.


Scrolling

set_scroll(sx, sy)

Sets the background scroll position.

ParamTypeDescription
sxu8Horizontal scroll (pixels)
syu8Vertical scroll (pixels)
let scroll_x = 0

on vblank:
    scroll_x := scroll_x + 1
    set_scroll(scroll_x, 0)

Scrolling wraps around at 256 pixels in both directions. The background layer scrolls independently of sprites.