Scrupp 0.1 Manual
Create your own 2D games and applications

Overview

At the beginning, Scrupp runs a Lua file which is chosen depending on the command line arguments. Read "Getting Started" for details. This file can run other Lua files, load any media type, define functions and so on. It has to define a table with the name 'main' which contains the callbacks.

Callbacks

render(delta)
This callback function is mandatory. It is executed in every frame. Scrupp calls it with delta as the only argument. This parameter holds the time in milliseconds which has passed since the last call to this function. This time should be about 20 ms long because Scrupp tries to make constant 50 frames per second. This information can be used to time animations. The rendering of images should happen in this function.
keypressed(key)
This callback function is optional. If a key is pressed then this function will be executed. Its only argument is the key constant. Read the section about Keyboard usage for details and an example.
keyreleased(key)
This callback function is optional. If a key is released then this function will be executed. Its only argument is the key constant. Read the section about Keyboard usage for details and an example.
mousepressed(x, y, button)
This callback function is optional. If a mouse button (including the mouse wheel) is pressed then this function will be executed. Read the section about Mouse usage for details and an example.
mousereleased(x, y, button)
This callback function is optional. If a mouse button (including the mouse wheel) is released then this function will be executed. Read the section about Mouse usage for details and an example.

Example

game.init("Callback Test", 600, 400, 32, false)

image = game.addImage(<image file>)

main = {
	render = function(dt)
		image:render(mouse.getX(), mouse.getY())
	end,
	
	mousepressed = function(x, y, button)
		print(button .." button pressed at "..x..", "..y)
	end,
	
	mousereleased = function(x, y, button)
		print(button .." button released at "..x..", "..y)
	end,
	
	keypressed = function(k)
		if k == key.ESCAPE then
			game.exit()
		end
		print("key with keycode " .. k .. " pressed")
	end,
	
	keyreleased = function(k)
		print("key with keycode " .. k .. " released")
	end
}	

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Mon Jun 01, 2009