APIReference: Difference between revisions
imported>Dddaaannn (API reference master article) |
imported>Dddaaannn No edit summary |
||
| Line 1: | Line 1: | ||
An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 [[CommandPrompt|command prompt]], using function syntax. | An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 [[CommandPrompt|command prompt]], using function syntax. | ||
== Calling APIs == | |||
Some APIs have optional arguments, indicated in this guide by square brackets around the argument name. To specify a value for an optional argument, you must specify values for all other arguments to the left in the argument list. | Some APIs have optional arguments, indicated in this guide by square brackets around the argument name. To specify a value for an optional argument, you must specify values for all other arguments to the left in the argument list. | ||
| Line 23: | Line 25: | ||
== The game loop == | == The game loop == | ||
If you define these functions in your code, Pico-8 will call them at specific times. See [[GameLoop| | If you define these functions in your code, Pico-8 will call them at specific times. See [[GameLoop|Game loop]]. | ||
* [[Init|<nowiki>_init()</nowiki>]] | * [[Init|<nowiki>_init()</nowiki>]] | ||
| Line 29: | Line 31: | ||
* [[Draw|<nowiki>_draw()</nowiki>]] | * [[Draw|<nowiki>_draw()</nowiki>]] | ||
If your code doesn't use the game loop, you can call this function to copy graphics to the screen: | If your code doesn't use the game loop, you can call this function to copy the graphics buffer to the screen: | ||
* [[Flip|<nowiki>flip()</nowiki>]] | * [[Flip|<nowiki>flip()</nowiki>]] | ||
| Line 35: | Line 37: | ||
== Graphics == | == Graphics == | ||
* [[ | * [[Camera|<nowiki>camera([x,] [y])</nowiki>]] | ||
* [[ | * [[Circfill|<nowiki>circfill(x, y, r, [col])</nowiki>]] | ||
* [[Circ|<nowiki>circ(x, y, r, [col])</nowiki>]] | |||
* [[ | * [[Clip|<nowiki>clip([x,] [y,] [w,] [h])</nowiki>]] | ||
* [[ | * [[Cls|<nowiki>cls()</nowiki>]] | ||
* [[Color|<nowiki>color(col)</nowiki>]] | |||
* [[Cursor|<nowiki>cursor(x, y)</nowiki>]] | |||
* [[Fget|<nowiki>fget(n, [f])</nowiki>]] | * [[Fget|<nowiki>fget(n, [f])</nowiki>]] | ||
* [[Fset|<nowiki>fset(n, [f,] [v])</nowiki>]] | * [[Fset|<nowiki>fset(n, [f,] [v])</nowiki>]] | ||
* [[Line|<nowiki>line(x0, y0, x1, y1, [col])</nowiki>]] | |||
* [[Palt|<nowiki>palt([c,] [t])</nowiki>]] | |||
* [[Pal|<nowiki>pal([c0,] [c1,] [p])</nowiki>]] | |||
* [[Pget|<nowiki>pget(x, y)</nowiki>]] | |||
* [[Print|<nowiki>print(str, [x,] [y,] [col])</nowiki>]] | * [[Print|<nowiki>print(str, [x,] [y,] [col])</nowiki>]] | ||
* [[ | * [[Pset|<nowiki>pset(x, y, [c])</nowiki>]] | ||
* [[Rectfill|<nowiki>rectfill(x0, y0, x1, y1, [col])</nowiki>]] | |||
* [[ | |||
* [[Rect|<nowiki>rect(x0, y0, x1, y1, [col])</nowiki>]] | * [[Rect|<nowiki>rect(x0, y0, x1, y1, [col])</nowiki>]] | ||
* [[ | * [[Sget|<nowiki>sget(x, y)</nowiki>]] | ||
* [[Spr|<nowiki>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</nowiki>]] | * [[Spr|<nowiki>spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])</nowiki>]] | ||
* [[Sset|<nowiki>sset(x, y, [c])</nowiki>]] | |||
* [[Sspr|<nowiki>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</nowiki>]] | * [[Sspr|<nowiki>sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])</nowiki>]] | ||
| Line 70: | Line 62: | ||
* [[Add|<nowiki>add(t, v)</nowiki>]] | * [[Add|<nowiki>add(t, v)</nowiki>]] | ||
* [[All|<nowiki>all(t)</nowiki>]] | |||
* [[Del|<nowiki>del(t, v)</nowiki>]] | * [[Del|<nowiki>del(t, v)</nowiki>]] | ||
* [[Foreach|<nowiki>foreach(t, f)</nowiki>]] | * [[Foreach|<nowiki>foreach(t, f)</nowiki>]] | ||
* [[Pairs|<nowiki>pairs(t)</nowiki>]] | * [[Pairs|<nowiki>pairs(t)</nowiki>]] | ||
| Line 82: | Line 74: | ||
== Sound == | == Sound == | ||
* [[Music|<nowiki>music([n,] [fade_len,] [channel_mask])</nowiki>]] | |||
* [[Sfx|<nowiki>sfx(n, [channel,] [offset])</nowiki>]] | * [[Sfx|<nowiki>sfx(n, [channel,] [offset])</nowiki>]] | ||
== Map == | == Map == | ||
* [[Map|<nowiki>map(cel_x, cel_y, sx, sy, cel_w, cel_h, [layer])</nowiki>]] | |||
* [[Mget|<nowiki>mget(x, y)</nowiki>]] | * [[Mget|<nowiki>mget(x, y)</nowiki>]] | ||
* [[Mset|<nowiki>mset(x, y, v)</nowiki>]] | * [[Mset|<nowiki>mset(x, y, v)</nowiki>]] | ||
== Memory == | == Memory == | ||
* [[Cstore|<nowiki>cstore(dest_addr, source_addr, len, [filename])</nowiki>]] | |||
* [[Memcpy|<nowiki>memcpy(dest_addr, source_addr, len)</nowiki>]] | |||
* [[Memset|<nowiki>memset(dest_addr, val, len)</nowiki>]] | |||
* [[Peek|<nowiki>peek(addr)</nowiki>]] | * [[Peek|<nowiki>peek(addr)</nowiki>]] | ||
* [[Poke|<nowiki>poke(addr, val)</nowiki>]] | * [[Poke|<nowiki>poke(addr, val)</nowiki>]] | ||
* [[Reload|<nowiki>reload(dest_addr, source_addr, len, [filename])</nowiki>]] | * [[Reload|<nowiki>reload(dest_addr, source_addr, len, [filename])</nowiki>]] | ||
== Math == | == Math == | ||
* [[ | * [[Abs|<nowiki>abs(x)</nowiki>]] | ||
* [[Atan2|<nowiki>atan2(dx, dy)</nowiki>]] | * [[Atan2|<nowiki>atan2(dx, dy)</nowiki>]] | ||
* [[Band|<nowiki>band(x, y)</nowiki>]] | * [[Band|<nowiki>band(x, y)</nowiki>]] | ||
* [[Bnot|<nowiki>bnot(x)</nowiki>]] | |||
* [[Bor|<nowiki>bor(x, y)</nowiki>]] | * [[Bor|<nowiki>bor(x, y)</nowiki>]] | ||
* [[Bxor|<nowiki>bxor(x, y, )</nowiki>]] | * [[Bxor|<nowiki>bxor(x, y, )</nowiki>]] | ||
* [[ | * [[Cos|<nowiki>cos(x)</nowiki>]] | ||
* [[Flr|<nowiki>flr(x)</nowiki>]] | |||
* [[Max|<nowiki>max(x, y)</nowiki>]] | |||
* [[Mid|<nowiki>mid(x, y, z)</nowiki>]] | |||
* [[Min|<nowiki>min(x, y)</nowiki>]] | |||
* [[Rnd|<nowiki>rnd(x)</nowiki>]] | |||
* [[Shl|<nowiki>shl(x, y)</nowiki>]] | * [[Shl|<nowiki>shl(x, y)</nowiki>]] | ||
* [[Shr|<nowiki>shr(x, y)</nowiki>]] | * [[Shr|<nowiki>shr(x, y)</nowiki>]] | ||
* [[Sin|<nowiki>sin(x)</nowiki>]] | |||
* [[Sqrt|<nowiki>sqrt(x)</nowiki>]] | |||
* [[Srand|<nowiki>srand(x)</nowiki>]] | |||
== Cartridge data == | == Cartridge data == | ||
Revision as of 01:26, 6 June 2016
An API is a function provided by Pico-8 that you can call from a cartridge's source code. You can also call API functions from the Pico-8 command prompt, using function syntax.
Calling APIs
Some APIs have optional arguments, indicated in this guide by square brackets around the argument name. To specify a value for an optional argument, you must specify values for all other arguments to the left in the argument list.
For example, the spr() function has three required arguments and four optional arguments:
spr( n, x, y, [w,] [h,] [flip_x,] [flip_y] )
This function can be called with three arguments, accepting the defaults for the others:
spr(1, 60, 60)
To specify a value for the flip_x argument, you must also specify w and h, even if you're using their default values:
spr(1, 60, 60, 1, 1, true)
The game loop
If you define these functions in your code, Pico-8 will call them at specific times. See Game loop.
If your code doesn't use the game loop, you can call this function to copy the graphics buffer to the screen:
Graphics
- camera([x,] [y])
- circfill(x, y, r, [col])
- circ(x, y, r, [col])
- clip([x,] [y,] [w,] [h])
- cls()
- color(col)
- cursor(x, y)
- fget(n, [f])
- fset(n, [f,] [v])
- line(x0, y0, x1, y1, [col])
- palt([c,] [t])
- pal([c0,] [c1,] [p])
- pget(x, y)
- print(str, [x,] [y,] [col])
- pset(x, y, [c])
- rectfill(x0, y0, x1, y1, [col])
- rect(x0, y0, x1, y1, [col])
- sget(x, y)
- spr(n, x, y, [w,] [h,] [flip_x,] [flip_y])
- sset(x, y, [c])
- sspr(sx, sy, sw, sh, dx, dy, [dw,] [dh,] [flip_x,] [flip_y])
Tables
Input
Sound
Map
Memory
- cstore(dest_addr, source_addr, len, [filename])
- memcpy(dest_addr, source_addr, len)
- memset(dest_addr, val, len)
- peek(addr)
- poke(addr, val)
- reload(dest_addr, source_addr, len, [filename])
Math
- abs(x)
- atan2(dx, dy)
- band(x, y)
- bnot(x)
- bor(x, y)
- bxor(x, y, )
- cos(x)
- flr(x)
- max(x, y)
- mid(x, y, z)
- min(x, y)
- rnd(x)
- shl(x, y)
- shr(x, y)
- sin(x)
- sqrt(x)
- srand(x)