Click.lua
Jump to navigation
Jump to search
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. |
defaultImg | The image that should be used when an image is not passed in loadCursor(). By default the image is hardcoded-42-2.png. |
dragBox
is a table containing information about the box created when the cursor is dragged.
Value | Description |
---|---|
active | If the mouse is being dragged. The next values won't update if this is false. |
startX | The starting X position of the box. |
startY | The starting Y position of the box. |
diagonal | The distance between the cursor and the starting point. |
width | The width of the box. |
height | The height of the box. |
top | The y coordinate of the top side of the box. |
bottom | The y coordinate of the bottom side of the box. |
left | The x coordinate of the left side of the box. |
right | The x coordinate of the right side of the box. |
Cursor Functions
Function | Description |
---|---|
loadCursor(table) | A table containing all different cursors that will be used. You may also pass nothing and it will create a default table for you. Each cursor is defined in a table. The values for each table is:
|
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.
|
circle{} | Will return true if the cursor is inside the specified circle.
|