Click.lua

From Moondust Wiki
Revision as of 21:29, 2 March 2018 by Pixelpest (talk | contribs)
Jump to navigation Jump to search

Download click.lua v1.1

Download click.lua v1.0

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.cursorLoad({
  {},
  {Graphics.loadImage("click.png"),5}
  {{Graphics.loadImage("imageA.png"),Graphics.loadImage("imageB.png")},5,0,0,10}
})
click.cursorSet(1)

function onTick()
  if click.click then 
    click.cursorSet(2)
  elseif click.released then
    click.cursorSet(1)
  end
  
  if click.box{x=player.x,y=player.y,width=player.width,height=player.height,scene=true,bool=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.
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.
sceneY Returns the Y-coordinate relative to the scene.
speedX Returns the X-speed of the cursor.
speedY Returns the Y-speed of the cursor.

Cursor Image Functions

Function Description
cursorLoad(table) A table containing all different cursors that will be used. Each cursor is defined in a table, and each value 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)
cursorSet(index) Set the cursor image using the index used in CursorLoad(). Use 0 to disable drawing the cursor.
cursorGet() Will return the current index of the cursor that is currently drawn.

Misc Functions

Function Description
box{} This function will return true if the cursor is inside the specified box.
  • Required Parameters
    • x - The x coordinate of the top left of the box.
    • y - The y coordinate of the top left of the box.
    • width - The width of the box.
    • height - The height of the box.
  • Optional Parameters
    • scene - Set to true to use coordinate values (default: false)
    • inverse - Set to true to check when the cursor is outside the specified box (default: false)
    • useXYXY - Set to true to change width and height into a second set of X, Y coordinates (default: false)
    • bool - Will act as an extra checker. If nil, it will turn to true. Reccomended for click.click, click.hold, click.released. (Default: nil)
    • name - Set to a string and it will add one every time this function return true. (Default: nil)
circle{} This function will return true if the cursor is inside the specified circle.
  • Required Parameters
    • x - The x coordinate of the center of the circle.
    • y - The y coordinate of the center of the circle.
    • radius - The radius of the box.
  • Optional Parameters
    • scene - Set to true to use coordinate values (default: false)
    • inverse - Set to true to check when the cursor is outside the specified box (default: false)
    • bool - Will act as an extra checker. If nil, it will turn to true. Recommended for click.click, click.hold, click.released. (Default: nil)
    • name - Set to a string and it will add one every time this function return true. (Default: nil)
findNameVal(name) Will return the name values used in box{} and circle{}.

Deprecated

If using v1.0 use these functions instead

setCursor() Image Path Priority X offset Y Offset Cursor
Sets the cursor with an image. The image's top-right corner will be drawn at the cursor. You can use the offsests to position the cursor when you need. Optional, string

Provide a file path to the image. NOTE: the API uses 'Misc.resolveFile', so use that to your advantage. Default: SMBX Cursor, "click/example"

Optional, number.

Provide the priority for the cursor. Default: 5

Optional, number.

Provide an X-offset for the image. Default: 0

Optional, number.

Provide a Y-offset for the image. Default: 0

Optional, boolean.

Choose if you want the cursor to appear. Default: True

setCursorOn() Delay
Turns on the image for the cursor. Optional, number

A delay for when the image should be turned on. Default: 0

setCursorOff() Delay
Turns off the image for the cursor. Optional, number

A delay for when the image should be turned off. Default: 0

cursorTimer() Type
Returns the timer until the cursor image is turned on/off Required, string

Have either "on", or "off".

isCursor
Returns true if the cursor is being displayed
sqr() Type X1 Y1 X2 Y2 Name
Check if the cursor is inside a square relative to the screen, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrIn() Type X1 Y1 X2 Y2 Name
Check if the cursor is outside a square relative to the screen, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrScene() Type X1 Y1 X2 Y2 Name
Check if the cursor is inside a square relative to the scene, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrSceneIn() Type X1 Y1 X2 Y2 Name
Check if the cursor is outide a square relative to the scene, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrFind() Name Set
Get the amount of frames a sqr function returned true using a name. Required, string.

Use the name to get the amount of frames using a name.

Optional, number.

Set the number for the name.