Skip to content
Vadim Grigoruk edited this page Apr 30, 2021 · 23 revisions

API

You can download a quick API reference sheet suitable for viewing or printing here: PDF or PNG. The Wiki also includes a Cheatsheet for fast reference.

Callbacks

Callbacks are functions that your game defines and that TIC-80 calls automatically. Every game at a minimum must define a TIC function.

  • TIC - Called 60 times per second (60 FPS); the main update/draw callback. Required.
  • SCN(n) - Called prior to each scanline render (allowing for palette swaps, etc).
  • OVR - Called last and draws to a separate layer (using a separate palette).

Sequencing

-- FRAME BEGINS (60 FPS)

   TIC()
   SCN(0) SCN(1) ... SCN(134) SCN(135)
   OVR()

-- FRAME END

Functions

Drawing

  • circ - Draw a filled circle
  • circb - Draw a circle border
  • elli - Draw a filled ellipse (0.90)
  • ellib - Draw an ellipse border (0.90)
  • clip - Set the screen clipping region
  • cls - Clear the screen
  • font - Print a string using foreground sprite data as the font
  • line - Draw a straight line
  • map - Draw a map region
  • pix - Get or set the color of a single pixel
  • print - Print a string using the system font
  • rect - Draw a filled rectangle
  • rectb - Draw a rectangle border
  • spr - Draw a sprite or composite sprite
  • tri - Draw a filled triangle
  • trib - Draw a triangle border (0.90)
  • textri - Draw a triangle filled with texture

Input

  • btn - Get gamepad button state in current frame
  • btnp - Get gamepad button state according to previous frame
  • key - Get keyboard button state in current frame
  • keyp - Get keyboard button state relative to previous frame
  • mouse - Get XY and press state of mouse/touch

Sound

  • music - Play or stop playing music
  • sfx - Play or stop playing a given sound

Memory

  • memcpy - Copy bytes from one location in RAM to another
  • memset - Set sequential bytes in RAM to a given value
  • pmem - Access or update the persistent memory
  • peek - Read a byte from an address in RAM
  • peek4 - Read a nibble (4bit) value from an address RAM
  • poke - Write a byte value to an address in RAM
  • poke4 - Write a nibble (4bit) value to an address in RAM
  • sync - Copy banks of RAM (sprites, map, etc) to and from the cartridge

Utilities

  • fget - Retrieve a sprite flag (0.80)
  • fset - Update a sprite flag (0.80)
  • mget - Retrieve a map tile at given coordinates
  • mset - Update a map tile at given coordinates

System

  • exit - Interrupt program and return to console
  • reset - Reset game to initial state (0.60)
  • time - Returns how many milliseconds have passed since game started
  • tstamp - Returns the current Unix timestamp in seconds (0.80)
  • trace - Print a string to the Console
Clone this wiki locally