Update: Difference between revisions

From Pico-8 Wiki
Jump to navigation Jump to search
imported>Felice Enellen
m (→‎See also: formatting)
imported>Felice Enellen
m (some time to kill = Felice pedantically fixes more PICO-8 capitalization)
Line 1: Line 1:
The first part of a [[GameLoop|game loop]] is normally an ''update''.  In PICO-8, this is done with either an <code>_update()</code> function, for 30fps games, or <code>_update60()</code> for 60fps games.  
The first part of a [[GameLoop|game loop]] is normally an ''update''.  In PICO-8, this is done with either an <code>_update()</code> function, for 30fps games, or <code>_update60()</code> for 60fps games.  


If a cartridge's source code includes both an <code>_update()</code> function and a <code>_draw()</code> function, then Pico-8 will attempt to call these functions once for each animation frame, at a rate of 30 frames per second for <code>_update()</code> or 60 frames per second with with <code>_update60()</code>.
If a cartridge's source code includes both an <code>_update()</code> function and a <code>_draw()</code> function, then PICO-8 will attempt to call these functions once for each animation frame, at a rate of 30 frames per second for <code>_update()</code> or 60 frames per second with with <code>_update60()</code>.


You define this function in your game's source code. It takes no arguments.
You define this function in your game's source code. It takes no arguments.

Revision as of 04:28, 30 April 2019

The first part of a game loop is normally an update. In PICO-8, this is done with either an _update() function, for 30fps games, or _update60() for 60fps games.

If a cartridge's source code includes both an _update() function and a _draw() function, then PICO-8 will attempt to call these functions once for each animation frame, at a rate of 30 frames per second for _update() or 60 frames per second with with _update60().

You define this function in your game's source code. It takes no arguments.

The intended purpose of _update() is to test for user inputs (button presses), perform all of the calculations to advance the state of the game, and update the game's data structures with the results. For example, you might compare the state of variables to see if the player's avatar is near an item during _update(). Typically, this function does not update the display, though it may initiate sound effects (sfx()) and music (music()).

See the entry on the game loop.

Examples

player_x=64
player_y=100

function _update()
  if(btn(0)) player_x-=1
  if(btn(1)) player_x+=1
end

See also