Changes

Jump to navigation Jump to search

timer.start

322 bytes added, 19:39, 7 January 2012
Line 22: Line 22:     
== Example ==
 
== Example ==
 +
 +
This example will display on the top-left corner of the screen a number going from 0 to infinity (it never stops), by adding 1 to ''variable'' every 0.5 seconds.
 +
 
<source>
 
<source>
 
variable = 0
 
variable = 0
    
function on.timer()
 
function on.timer()
   timer.stop()
+
   timer.stop() -- stops the current timer. Not necessary.
 
   variable = variable + 1
 
   variable = variable + 1
   platform.window:invalidate()
+
   platform.window:invalidate()  -- screen refresh (on.paint is called)
 
end
 
end
    
function on.paint(gc)
 
function on.paint(gc)
   timer.start(0.5)
+
   timer.start(0.5) -- will fire the on.timer event every half second.
   gc:drawString(variable,0,0,"top")
+
   gc:drawString(variable,0,0,"top") -- display the number
 
   
end</source>
 
end</source>
  

Navigation menu