Difference between revisions of "on.timer"

From Inspired-Lua Wiki
Jump to navigation Jump to search
(Created page with " Category:Events")
 
Line 1: Line 1:
 +
 +
The event '''on.timer''' is fired when a [[:Category:timer|timer]] is run.
 +
 +
By default, it has no argument, but you can pass gc to it for instance.
 +
 +
== Example ==
 +
 +
Below is an example of a program that draws a line on the screen when the user resizes the window :
 +
<source lang="lua">
 +
 +
  function on.paint(gc)
 +
if message then
 +
gc:setFont("sansserif", "r", 10) -- initialize font drawing
 +
gc:drawString(message, 0, 0, "top") -- display the message at (0, 0) coordinates
 +
message = nil -- erase the message
 +
timer.start(1) -- start a timer to exit on.paint() but keep in mind that we have to redraw the screen
 +
end
 +
  end
 +
 +
  function on.timer()
 +
timer.stop()
 +
platform.window:invalidate()
 +
  end
 +
 +
  function on.charIn(ch)
 +
message = "Hello World !" -- store a message
 +
platform.window:invalidate() -- force display
 +
  end
 +
</source>
 +
 +
Check out the [http://www.inspired-lua.org/2011/05/linking-events/ the full explanation of this example] in the tutorials part.
  
  
 
[[Category:Events]]
 
[[Category:Events]]

Revision as of 13:07, 6 July 2011

The event on.timer is fired when a timer is run.

By default, it has no argument, but you can pass gc to it for instance.

Example

Below is an example of a program that draws a line on the screen when the user resizes the window :

  function on.paint(gc)
 	if message then
 	 	gc:setFont("sansserif", "r", 10)	-- initialize font drawing
 	 	gc:drawString(message, 0, 0, "top")	-- display the message at (0, 0) coordinates
 	 	message = nil 				-- erase the message
 	 	timer.start(1) 	 	 	-- start a timer to exit on.paint() but keep in mind that we have to redraw the screen
 	end
   end

   function on.timer()
 	timer.stop()
 	platform.window:invalidate()
   end

   function on.charIn(ch)
 	message = "Hello World !"		-- store a message
 	platform.window:invalidate()		-- force display
   end

Check out the the full explanation of this example in the tutorials part.