Game engine functions - Protovision/io-lua GitHub Wiki
Error handling will not need to be done by Lua. If any of these functions fail, the game engine will display a message box error and then abort.
Image functions
- LoadImage(filename) - Loads a jpeg or png image from a file. filename will be searched in the game archive first; if it is not found, then it will be searched in the base archive. Returns a handle to that image.
- DrawImage(x, y, image, [w, h]) - Draws an image to the coordinates (x, y) in the game window. If w and h are specified, they refer to the width and height to stretch the image as before drawing.
- DrawClip(dst_x, dst_y, image, src_x, src_y, src_w, src_h, [dst_w, dst_h]) - Draws a rectangular portion of an image to the game window. dst_x and dst_y are the coordinates to draw to. image is a handle to an image loaded with LoadImage. src_x, src_y, src_w, and src_h specify the rectangle to draw from using image. dst_w and dst_h optionally specify the width and height to scale the clipped image to before drawing.
- DrawBackground(image) - Draws an image to fill the entire window.
- FreeImage(image) - Releases the resources used by an image handle.
- GetImageSize(image) - Returns the width and height of a loaded image.
- FadeImage(image, alpha) - Set the alpha value of an image
Text functions
- LoadFont(filename, [size]) - Loads a font from a file relative to gamepath. filename will be searched in the game archive first; if it is not found, then it will be searched in the base archive. If size is specified, the font will be loaded with size; otherwise the default the value of the game engine variable fontsize will be used. Returns a handle to that font.
- DrawText(x, y, text, [color, font]) - Draws text to the coordinates (x, y) in the game window. If specified, color refers to an rgba integer value (see base/scripts/constants.lua for a list of pre-defined colors). If specified, font refers to a handle opened with LoadFont. The default color is the color set through the fgcolor game engine variable. The default font is FONT_SANS.
- FreeFont(font) - Releases the resources used by a font handle.
- GetTextSize(text, font) - Returns the width and height of text if it were rendered with font.
Drawing functions
- SetColor(color) - Sets the drawing color. color is an rgba integer value.
- Clear() - Fills the window with the current drawing color.
- DrawLine(x1, y1, x2, y2) - Draws a line.
- DrawRect(x, y, w, h) - Draws a rectangle.
- FillRect(x, y, w, h) - Fills a rectangular region with the current drawing color.
Cursor functions
- LoadCursor(filename, hotx, hoty) - Creates a cursor and uses the png image loaded by filename as the image. hotx and hoty specify the coordinates in the image of the cursor hotspot. Returns a handle to the loaded cursor.
- SetCursor(cursor) - Sets the active cursor
- GetCursor(cursor) - Returns a handle to the current active cursor
- FreeCursor(cursor) - Use this function to free a cursor created by LoadCursor
Sound and audio functions
- LoadSound(filename) - Loads a wav or ogg file relative to gamepath. filename will be searched in the game archive first; if it is not found, then it will be searched in the base archive. Returns a handle to the loaded sound.
- PlaySound(sound, [loop, fadein]) - Begins playing a sound from a sound handle. Returns a handle to the new sound channel. If loop is true, the sound will play in a loop. If fadein is > 0, the sound will fade in from silence to full volume in fadein seconds.
- PauseSound(channel) - Pauses a sound channel. If channel is -1, pauses all sounds.
- ResumeSound(channel) - Resumes a paused sound channel. If channel is -1, resumes all sounds.
- StopSound(channel) - Stops playing a sound channel. If channel is -1, stops all sounds.
- GetSoundVolume(channel) - Gets the volume of a playing sound channel. If channel is -1, gets the average volume of all channels.
- SetSoundVolume(channel) - Sets the volume of a playing sound channel. If channel is -1, sets the volume for all channels.
- FreeSound(sound) - Releases the resources used by a sound handle.
- FadeSound(channel, seconds) - Fade out a playing sound.
Filesystem functions
- LoadData(filename) - Returns the contents of a file into a string. filename will be searched in the game archive first, if it is not found then it will be searched in the base archive.
- LoadFile(filename) - Returns the contents of a file into a string. filename will be searched relative to the datapath.
- SaveFile(filename, data, [len]) - Writes the string data into the file specified by filename. filename is relative to datapath. If len is specified, this function will write the first len characters from data into the file.
- CheckFile(filename) - Checks if a file exists in the datapath directory.
- RenameFile(oldfilename, newfilename) - Renames a file relative to datapath.
- RemoveFile(filename) - Removes a file relative to datapath.
- MakeDirectory(dirname) - Creates a directory relative to datapath.
- OpenFile(filename, mode) - Opens a file relative to datapath. mode is an fopen-style mode. Returns a handle to the opened file.
- ReadFile(filehandle) - Reads the next line from the file handle and returns it as a string without the new line. If at end of file, this function will return an empty string.
- WriteFile(filehandle, string) - Writes a string into a file given by it's file handle.
- IsEof(filehandle) - Returns true if the file position for filehandle is at the end of the file.
- SeekFile(filehandle, offset, whence) - Sets the file position of the file handle relative to whence. whence can be SEEK_SET, SEEK_CUR, or SEEK_END for: the beginning of the file, the current file position, or the end of the file respectively. Returns the resulting absolute file offset.
- TellFile(filehandle) - Equivalent to SeekFile(filehandle, 0, SEEK_CUR). Returns the current file offset.
- CloseFile(filehandle) - Closes the file referred to by file handle.
- ReadDirectory(pathname) - Reads all the filenames stored in the specified directory (relative to datapath) and returns the list as a table.
- IsFile(filename) - Returns true if the pathname in datapath is a regular file.
- IsDirectory(filename) - Returns true if the pathname in datapath is a directory.
Other functions
- Call(luafile) - Executes a lua file. The file will be searched in the game archive first, then the base archive. Returns any values returned by the Lua file.
- GetPlatform() - Returns "Windows", "Linux", or "Mac OS X" depending on your platform.
- MessageBox(message) - Displays a message box.
- Get(variable) - Gets the value of a game engine variable as a string.
- Set(variable, value) - Sets the value of a game engine variable through a string.
- GetWindowSize() - Returns the width and height of the window
- GetMousePosition() - Returns the x and y coordinates of the mouse cursor in the game window
- GetTicks() - Gets the number of clock ticks passed since the game started running.
- Quit() - Quits the game.