Page 1 of 1

Click.lua

Posted: Wed Jan 04, 2017 12:13 pm
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.
Example 1: show
Image

Code: Select all

local click = API.load("click")
click.cursorLoad({{}})
click.cursorSet()
Example 2: show
Image

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
Example 3: show
Image

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
Example 4: show
Image

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

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

Re: Click.lua

Posted: Wed Jan 04, 2017 6:47 pm
by ivanmegafanboy
Holy thwomp, that is so cool. Like for puzzle levels or "editor-PGE" themed levels.

Re: Click.lua

Posted: Sat Jan 07, 2017 5:53 pm
by kr4k1n
So, technically you can now use the mouse as one of the controls for a game. I've never seen the mouse before until now, and it looks like it's one Mario's hands, that's cool!

Re: Click.lua

Posted: Sun Jan 08, 2017 12:54 am
by Yoshi021
practicalshorty014 wrote:So, technically you can now use the mouse as one of the controls for a game. I've never seen the mouse before until now, and it looks like it's one Mario's hands, that's cool!
You can set the image to the cursor you want, but there is a default image. Use setCursor() for that.

Re: Click.lua

Posted: Fri May 19, 2017 10:01 am
by Yoshi021
Click v1.1 has been released. There is a new system to set the image cursor that now allows animated images, and a new box{}, and circle{} functions that make using the cursor easier. The download is in the documentation.

Re: Click.lua

Posted: Sat May 20, 2017 2:27 am
by ElectriKong
Is there a way this could be used to pick up specific items? Then we could make episodes like SMG where the cursor could pick up starbits.