Game Development Reference
In-Depth Information
The Callback Functions
The callback functions that we can override to make LÖVE work for us are described in this section.
love.load ( )
This function is called when the game starts; it's similar to the window_onLoad function in JavaScript
or the main() entry point in C. This is called only once, and it is used to perform tasks like loading
the resources, setting specific settings, initializing variables, and so on. In an object-oriented setting,
think of this as the constructor; it is run only once, when a LÖVE applications starts.
love.update ( dt )
This function is called almost continuously. This is like an enterFrame event or the heartbeat of the
application. The parameter passed to the function is dt , which is the delta time —the amount of time
since the function was last called, in seconds. This can be a very small value—as small as 0.025714
seconds (depending on your platform). Frame rates can also affect the delta time.
love.draw ( )
This is the function where all the onscreen drawing takes place. If you have had any previous experience
with development using Visual C++, MFC, ATL, OWL, or Objective-C, you will be familiar with this type
of function. If any of the draw commands are called outside of this function, they will have no effect.
love.mousepressed ( x, y, button )
This function is called whenever a mouse button is pressed; this function is a handler for the mouse
button's down event and is passed the x- and y-coordinates of where the mouse button was
pressed. It also gets which mouse button was pressed: left, right, or middle.
love.mousereleased ( x, y, button )
This function is called when the mouse button is released; it acts as a handler for the mouse button's
release event and is passed the x-and y-coordinates of where the mouse button was released and
which mouse button was released.
love.keypressed ( key, unicode )
This function is called when a key is pressed on the keyboard; this function acts as a handler for the
keypress down event and is passed the key code. The key parameter holds the character of the key
pressed and the unicode parameter holds the ASCII code of the key. If you press the key a , then
key would be a and unicode would be 97 .
 
Search WWH ::




Custom Search