Page 1 of 1

Click.lua

Posted: 4 Jan 2017, 20:14
by Yoshi021
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.

EXAMPLES
Example 1
Image

Code: Select all

local click = API.load("click")
click.setCursor()
Example 2
Image

Code: Select all

local click = API.load("click")
click.setCursor()

function onTick()
  if click.hold then
    click.setCursor("Goomba.png")
    NPC.spawn(1,click.sceneX,click.sceneY,player.section)
  else
    click.setCursor("click/example.png")
  end
end
Example 3
Image

Code: Select all

local click = API.load("click")
click.setCursor("Goomba.png")
click.setCursorOff()

function onTick()
  if click.click() then
    click.setCursorOn()
    click.setCursorOff(15)
    NPC.spawn(1,click.sceneX,click.sceneY,player.section)
  end
end
Example 4
Image

Code: Select all

local click = API.load("click")
click.setCursor()

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
Example 5
Image

Code: Select all

local click = API.load("click")
click.setCursor()
click.setCursorOff()

function onTick()
  Text.print(click.sqrFind("example"),0,0)
  if click.sqr(click.click,0,0,800,32,"example") then
    player.speedY = -5
  end
  if click.click then
    click.setCursorOn()
    click.setCursorOff(15)
  end
end
Example 6
Image

Code: Select all

local click = API.load("click")
click.setCursor()

function onTick()
  if math.abs(click.speedX) > 50 or math.abs(click.speedY) > 50 then
    Defines.earthquake = 5
  end
end


NOTE
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.

Posted: 11 Jan 2017, 2:10
by Zwertll
I liked. Depending on how you use it on one level can be quite useful since it can do several things. It can be cool for gimmicks and minigames.