From 097fa8b0909c16c537fc15c5c8eebc301bfc94ca Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Tue, 12 Apr 2011 12:56:45 +0200 Subject: [PATCH] Document gamestate:init() --- index.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index d766764..fa0ff6f 100644 --- a/index.html +++ b/index.html @@ -133,6 +133,8 @@

A gamestate can define (nearly) all callbacks that LÖVE defines. In addition, there are callbacks for entering and leaving a state.:

+
init()
+
Called once before entering the state. See switch().
enter(previous, ...)
Called when entering the state. See switch().
leave()
@@ -163,13 +165,13 @@
Example:
menu = Gamestate.new()
-function menu:enter(previous, background_image)
-    self.background = background_image
+function menu:init() -- run only once
+    self.background = love.graphics.newImage('bg.jpg')
     Buttons.initialize()
 end
 
-function menu:leave()
-    Buttons.cleanup()
+function menu:enter(previous) -- run every time the state is entered
+    Buttons.setActive(Buttons.start)
 end
 
 function menu:update(dt)
@@ -228,8 +230,9 @@ end
function switch(to, ...)^ top

Switch to a gamestate, with any additional arguments passed to the new state.

Switching a gamestate will call the leave() callback on - the current gamestate, replace the current gamestate with to and finally call - enter(old_state, ...) on the new gamestate.

+ the current gamestate, replace the current gamestate with to, call the + init() function if the state was not yet inialized and + finally call enter(old_state, ...) on the new gamestate.

Parameters:
Gamestate to