Download click.lua v1.2 BETA
A small library for the cursor. You can find its coordinates in the scene, find the speed's cursor, or set an image cursor.
Installation
Place the file click.lua in either your level's custom graphics folder for use in a level, along with a lunadll.lua file, or in the same directory as your .wld file along with a lunaworld.lua file for use throughout an entire episode.
How to Use
To enable the click.lua, add this line to lunadll.lua:
local click = API.load("click");
This will load the API.
Example
local click = API.load("click")
click.loadCursor({
{Graphics.loadImage("click.png")}
{{Graphics.loadImage("imageA.png"),Graphics.loadImage("imageB.png")}, 5, 0, 0, 10}
})
click.setCursorID(1)
function onTick()
if click.click then
click.setCursorID(2)
elseif click.released then
click.setCursorID(1)
end
if click.box{x = player.x, y = player.y, width = player.width, height = player.height, scene = true} and click.click then
player:kill()
end
end
Documentation
Cursor Values
| Name
|
Description
|
| click
|
Returns true for the first frame the mouse was clicked.
|
| hold
|
Returns true if the mouse is being held.
|
| released
|
Returns true for the first frame the mouse was released.
|
| state
|
Returns the state of the cursor. Compatible with KEYS_UP, KEYS_DOWN, KEYS_PRESS, and KEYS_UNPRESSED. [Only for SMBX2 Beta 4 or higher]
|
| x
|
Returns the X-coordinate relative to the screen.
|
| y
|
Returns the Y-coordinate relative to the screen.
|
| sceneX
|
Returns the X-coordinate relative to the scene. Will return nil if the cursor is not inside any of the cameras.
|
| sceneY
|
Returns the Y-coordinate relative to the scene. Will return nil if the cursor is not inside any of the cameras.
|
| speedX
|
Returns the X-speed of the cursor.
|
| speedY
|
Returns the Y-speed of the cursor.
|
Cursor Functions
| Function
|
Description
|
| loadCursor(table)
|
A table containing all different cursors that will be used. Each cursor is defined in a table, and each value except for image is optional. The values for each table is:
- The image of the cursor, or a table of images if the cursor is animated.
- Priority of the cursor
- X offset
- Y offset
- Animation Speed (Only if the cursor is animated)
|
| setCursorID(index)
|
Set the cursor image using the index used in loadCursor(). Use 0 to disable drawing the cursor.
|
| getCursorID()
|
Will return the current index of the cursor that is currently drawn.
|
Misc. Functions
| Function
|
Description
|
| box{}
|
Will return true if the cursor is inside the specified box.
- Required Parameters
- x The X-coordinate left side of the box.
- y The Y-coordinate top side of the box.
- width The width of the box.
- height The height of the box.
- Optional Parameters
- scene Set to true to use scene coordinates. [Default: False]
- useXY2 Will instead use the parameters 'X2' 'Y2' to represent the bottom and right side of the box intead of using width and height. [Default: False]
|
| circle{}
|
Will return true if the cursor is inside the specified circle.
- Required Parameters
- x The X-coordinate center of the circle.
- y The Y-coordinate center of the circle.
- radius The radius of the circle.
- Optional Parameters
- scene Set to true to use scene coordinates. [Default: False]
|