Hello! Today I present click.lua a library that allows you to use the cursor, and the left mouse button. The API allows you to set a cursor image, check its position from the screen or scene, check if the mouse is clicked/held/released, and identify the mouse in squares. The cursor is a feature that I have never seen in SMBX, and I hope you can take its full advantage! I present to you some examples.

Code: Select all
local click = API.load("click")
click.cursorLoad({{}})
click.cursorSet()

Code: Select all
local click = API.load("click")
click.cursorLoad({
{Graphics.loadImage("goomba.png")},
{}
})
function onTick()
if click.hold then
click.cursorSet(1)
NPC.spawn(1,click.sceneX,click.sceneY,player.section)
else
click.cursorSet(2)
end
end

Code: Select all
local click = API.load("click")
click.cursorLoad()
click.cursorSet(1)
function onTick()
for k,v in pairs(NPC.get()) do
v.speedX = (click.sceneX - v.x)/50
v.speedY = (click.sceneY - v.y)/50
end
end

Code: Select all
local click = API.load("click")
click.cursorLoad()
function onTick()
Text.print(click.findNameVal("example"),0,0)
if click.box{bool=click.click,x=0,y=0,width=800,height=32,name="example"} then
player.speedY = -5
end
if click.click then
click.cursorSet(1)
elseif click.released then
click.cursorSet(0)
end
end

Code: Select all
local click = API.load("click")
click.cursorLoad()
click.cursorSet(1)
function onTick()
if math.abs(click.speedX) > 50 or math.abs(click.speedY) > 50 then
Defines.earthquake = 5
end
end
In SMBX, for some reason, it has trouble identifying fast double clicks. I am not sure why but this is SMBX's fault. You can test this in the episode select menu, and see the same result.
Documentation:
http://wohlsoft.ru/pgewiki/Click.lua
If you see any errors, please tell me as soon as possible so I can fix them.