1
Getting an Image to be Clickable
Started by Persona, Jan 09 2013 01:38 PM
5 replies to this topic
#1
Posted 09 January 2013 - 01:38 PM
The image above shows you what I am trying to accomplish. I want the whole button (NOT the screen) to be clickable. I've browsed and found stuff on OS.PULLEVENT() and it is CLOSE to what I need, but I've only been able to make the whole screen activate.
I want the button (the 5 by however wide the terminal is)..
#3
Posted 09 January 2013 - 02:01 PM
I would suggest using a range to check whether a click that occurred was on your button.
If your button starts at the origin of the screen (1, 1), is 5 high, and extends to the end of the screen (50?), I would suggest doing something like this:
I'd be glad to clarify any of the above code if you need some help.
If your button starts at the origin of the screen (1, 1), is 5 high, and extends to the end of the screen (50?), I would suggest doing something like this:
local button_xPos, button_yPos = 1, 1 local buttonWidth, buttonHeight = 50, 5 -- Checks whether or not the click at the given position was -- within the range provided. function wasClickOnRange(xClickPos, yClickPos, xRangeStart, yRangeStart, rangeWidth, rangeHeight) return (xClickPos >= xRangeStart or xClickPos <= xRangeStart + rangeWidth) and (yClickPos >= yRangeStart or yClickPos <= yRangeStart + rangeHeight) end -- A more specific function to check if a click was on our button. function wasClickOnButton(xClickPos, yClickPos) return wasClickOnRange(xClickPos, yClickPos, button_xPos, button_yPos, buttonWidth, buttonHeight) end -- Grabs a click, checks whether or not it was on the button, then -- performs the appropriate action. function handleClicks() local event, mouseButton, xClickPos, yClickPos = os.pullEvent("mouse_click") -- Check if the click we got was on our button. if wasClickOnButton(xClickPos, yClickPos) then -- Do whatever you want here. end end
I'd be glad to clarify any of the above code if you need some help.
#4
Posted 09 January 2013 - 02:04 PM
Simple, make a condition that checks for the mouse click into the designated area:
local sEvent,button,x,y = os.pullEvent("mouse_click") if (x >= minX or x <= maxX) and (y >= minY or y <= maxY) then -- Replace min/max values for the corners of the button, in order to make a box Do stuff end
#5
Posted 09 January 2013 - 04:15 PM
Thank you everyone for your advice. I used the reply by this person
Heracles421, on 09 January 2013 - 02:04 PM, said:
Simple, make a condition that checks for the mouse click into the designated area:
local sEvent,button,x,y = os.pullEvent("mouse_click") if (x >= minX or x <= maxX) and (y >= minY or y <= maxY) then -- Replace min/max values for the corners of the button, in order to make a box Do stuff end
#6
Posted 10 January 2013 - 07:09 PM
Actually, it should be:
if (x >= minX and x <= maxX) and (y >= minY and y <= maxY)
Because using "or" the condition will be true no matter where you click on the screen.
(no "code" tags because code blocks don't accept bold formatting)
if (x >= minX and x <= maxX) and (y >= minY and y <= maxY)
Because using "or" the condition will be true no matter where you click on the screen.
(no "code" tags because code blocks don't accept bold formatting)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users