Cursor.lua

From Moondust Wiki
Jump to navigation Jump to search

Download: cursor.lua v1.0


Cursor.lua is a library specialized in helping you use and customize the cursor in SMBX.


Installation

local cursor = require("cursor")

Load the cursor library by placing the cursor.lua file in the level directory and loading it as shown above.


Documentation

Values

Name Type Description
x number The X position of the cursor relative to the screen
y number The Y position of the cursor relative to the screen
sceneX number The X position of the cursor relative to the scene
sceneY number The Y position of the cursor relative to the scene
speedX number The X-speed of the cursor
speedY number The Y-speed of the cursor
screenPos point collider A collider object of the cursor. The position is set to the position relative to the screen
scenePos point collider A collider object of the cursor. The position is set to the position relative to the scene
onscreen boolean Will return true if the cursor is inside the window screen.
onscene boolean Will return true if the cursor is inside a camera window.
camera number Will return the current camera being used for sceneCoordinates. Returns 0 if none is found.
left keystate The key state of the left button of the mouse. To be used just like player.keys
right keystate The key state of the right button of the mouse. To be used just like player.keys. BECAUSE OF A BUG IN SMBX, ONLY cursor.right == KEYS_PRESSED WORKS
leftDragBox box collider A rectangle collider of the box formed when the cursor is dragged across the screen. You can also do leftDragBox.timer to check how many frames the box has been active.
leftDragBoxScene box collider A rectangle collider of the box formed when the cursor is dragged across the screen. The position is relative to the scene. You can also do leftDragBox.timer to check how many frames the box has been active.

Cursor Images

Use the following functions to create a customizable cursor image.

Function Name Parameters Return Value Description
cursor.create(data, noset) data: table of parameters

noset: boolean

id Creates a cursor image with the parameters declared by the data table. It will automatically set the image into the cursor unless noset is set to true.
cursor.setID(id) id: number Sets the image of the ID based on the passed ID. Set to 0 or nil to turn off the cursor image.
cursor.getID() id Returns the current image ID.

Use the table cursor.imgCur to change different parameters of the current cursor that is being drawn.

Values of imgCur
Name Description
image The image that should be drawn.
offsetx An X offset that will shift the image horizontally.
offsetY A Y offset that will shift the image horizontally.
frames The total amount of frames.
framespeed How many frames should the game wait in-between frames.
animationTimer A timer that counts up. If the timer is that equal to framespeed, the frames updates.
frame The current frame that is being drawn.
color A color hue that should be applied to the image
angle Rotates the image in degrees.


Every value is optional when creating a cursor image, so if you need a quick cursor image for debug purposes, something this simple will work!

local cursor = require("cursor")

-- Creates a cursor image with all the default values
cursor.create()

Settings

Name Description
defaultcam1 If the camera is not inside a camera screen, it will use camera 1 to calculate its values. DEFAULT: TRUE
debug If set to true, it will print debug information onscreen. DEFAULT: FALSE