Free PICO-8 Cheat Sheet
A one-page printable reference for the PICO-8 game loop, input, drawing, sound, memory and the most-used Lua patterns. Pin it next to your monitor!
A one-page printable reference for the PICO-8 game loop, input, drawing, sound, memory and the most-used Lua patterns. Pin it next to your monitor!
function _init() 0 end function _update() if btn(0) then x -= 2 end if btn(1) then x += 2 end end function _draw() 0) spr(1, x, y) end
| btn(0) | D-Pad Left |
| btn(1) | D-Pad Right |
| btn(2) | D-Pad Up |
| btn(3) | D-Pad Down |
| btn(4) | ๐ / Z button |
| btn(5) | โจ / X button |
| btn(6) | Left shoulder (NES) |
| btn(7) | Right shoulder (NES) |
| btnp() | Pressed this frame (auto-repeat) |
| btn(0,1) | Check player 1 (or use p1/p2 flag) |
| cls(c) | Clear screen with colour c |
| spr(n,x,y) | Draw sprite n at x,y |
| map(mx,my,sx,sy) | Draw map tiles from map pos to screen |
| rect(x1,y1,x2,y2,c) | Outline rectangle |
| rectfill(x1,y1,x2,y2,c) | Filled rectangle |
| circ(x,y,r,c) | Outline circle |
| circfill(x,y,r,c) | Filled circle |
| line(x1,y1,x2,y2,c) | Draw a line |
| print(str,x,y,c) | Draw text at x,y |
| pset(x,y,c) | Set a single pixel |
-- play sfx number n sfx(0) -- play music starting at pattern 0 music(0) -- stop all music music(-1) -- set sfx playback speed sfx(0, -1, 0, 8) -- memory-mapped sfx registers poke(0x3200, 1) -- channel 0 volume
| peek(addr) | Read a byte from memory address |
| poke(addr,val) | Write a byte to memory address |
| mget(x,y) | Get map tile at grid position |
| mset(x,y,v) | Set map tile at grid position |
| sget(x,y) | Get pixel from sprite sheet |
| sset(x,y,c) | Set pixel on sprite sheet |
| memcpy(dst,src,len) | Copy memory region |
| memset(addr,val,len) | Fill memory region |
Sprites: 0x0000-0x1FFF ยท Map: 0x2000-0x2FFF ยท Sprite flags: 0x3000-0x30FF
| flr(n) | Floor (round down) |
| ceil(n) | Ceil (round up) |
| rnd(n) | Random float 0 to n |
| srand(seed) | Seed the RNG |
| abs(n) | Absolute value |
| sin(a) | Sine (-1 to 1, angle 0-1) |
| cos(a) | Cosine (0 to 1, angle 0-1) |
| atan2(dy,dx) | Angle from two points (0-1) |
| sqrt(n) | Square root |
| min(a,b) / max(a,b) | Minimum / Maximum |
-- tables (arrays) enemies = {} add(enemies, {x=10, y=20}) del(enemies, enemies[1]) for e in all(enemies) do e.x += 1 end -- strings s = "hello" len = #s sub = sub(s, 1, 3) -- "hel" tonum("42") -- โ 42 tostr(42) -- โ "42"
| t() | Time since start (seconds) |
| time() | Alias for t() |
| stat(x) | System stats (CPU, memory, etc) |
| pmem(n) | Persistent cart memory (0-255) |
| btn(0)โbtn(7) | Bitfield: band(btn(),0xf) |
| cbtn() | Continuous button state |
| cartdata(id) | Open persistent data slot |
| dget(n) / dset(n,v) | Get/set cartdata values |
โโ SPRITE ANIMATION โโ frame = 0 function _update() frame += 0.25 if frame >= 4 then frame = 0 end end function _draw() spr(1 + flr(frame), x, y) end โโ CAMERA FOLLOW โโ function _draw() cam_x = player.x - 64 cam_y = player.y - 64 camera(cam_x, cam_y) -- draw world here end โโ SIMPLE COLLISION โโ function collide(a, b) return a.x < b.x+8 and a.x+8 > b.x and a.y < b.y+8 and a.y+8 > b.y end โโ TILE COLLISION (MAP) โโ function solid(x, y) return mget(flr(x/8), flr(y/8)) > 0 end โโ TIMER / COUNTDOWN โโ timer = 60 function _update() if timer > 0 then timer -= 1 end end
Follow one of our free step-by-step workshops in the Workshop hub.
๐ง Browse Workshops โ