Fandom

Pico-8 Wiki

Multiple States System

162pages on
this wiki
Add New Page
Comments0 Share

Description Edit

Ever wanted a Title Screen or a Menu?

This guide can show you how to manage multiple states at the same time!

Note: For examplatory purposes, we'll be using the prefixes "game" and "title" for this tutorial.

Instructions Edit

Edit

Initializing Edit

The function "_init()" is what happens when the game is started up (or in this case, the State).

function _init()
  titleinit() -- does title things.
end

function titleinit()
  mode = 0
  --whatever you wish to do when the title starts up.
end

function gameinit()
  mode = 1
  --what to do at the start of the play session.
end

We'll call on gameinit() later.

Updating Edit

The function "_update()" is where gameplay elements are changed (like a timer).

function _update()
  if (mode == 0) then --Title Screen mode
    titleupdate()
  else
    gameupdate()
  end
end

function titleupdate()
  --Example "Press Z to start"
  --if btn(4,0) then
  --  gameinit()
  --end
end

function gameupdate()
  --gameplay elements (or whatever used to be in _update) goes here.
end

The example given can be used by simply getting rid of the dashes (or rather uncommenting it).

Drawing Edit

The function "_draw()" is called to draw things to the screen. (There's some repetition in this one.)

function _draw()
  if (mode == 0) then --Title Screen mode
    titledraw()
  else
    gamedraw()
  end
end

function titledraw()
  --Example "Title"
  --print("Super Cool Game")
end

function gamedraw()
  --the screen drawing mechanisms(or whatever used to be in _draw) goes here.
end

Notes Edit

- If you want to add more to "_draw" or "_update", simply follow this guideline:

else if (mode == 2) then
    --optiondraw() or optionupdate()

just be sure to put that before the else statement!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.