![Cry :cry:](./images/smilies/ms-cry.png)
How to make a clicked image (button) draw an image[SOLVED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 3
- Joined: Sun Aug 28, 2016 3:54 am
How to make a clicked image (button) draw an image[SOLVED]
I made a button with is currenctly a .png file and i want it to make another image appear when it is left clicked by the mouse, please help thanks. ![Cry :cry:](./images/smilies/ms-cry.png)
![Cry :cry:](./images/smilies/ms-cry.png)
Last edited by InfamousMakundo on Sat Oct 01, 2016 12:53 am, edited 1 time in total.
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: How to make a clicked image (button) draw an image
If I understand you correctly, you have a button image, and once you right-click it an image shows up on screen, like a pop-up, right? If so:
Code: Select all
function love.load()
--This is one way of making a button. You can make it however you want, even use pre-made libraries
myButton = {
x = 10, y = 10, image = love.graphics.newImage("myButton.png"), clicked = false
}
--This is just an easy way to know the pop-up image and where to draw it. Change to whatever you want
myImage = {
x = 50, y = 50, image = love.graphics.newImage("myImage.png")
}
end
function love.draw()
love.graphics.draw(myButton.image, myButton.x, myButton.y) --This is where we draw your button
if myButton.clicked then --If the person clicked the button, this will be true
love.graphics.draw(myImage.image, myImage.x, myImage.y) --This is where we draw the pop-up image
end
end
function love.mousepressed(x, y, button)
if button == 1 then --Left click
if x >= button.x and x <= button.x+button.image:getWidth() and y >= button.y and y <= button.y+button.image:getHeight() then --Detect if the click was inside the button
button.clicked = true --This is what triggers the pop-up image
end
end
end
Last edited by HugoBDesigner on Mon Aug 29, 2016 2:19 pm, edited 1 time in total.
- zorg
- Party member
- Posts: 3449
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to make a clicked image (button) draw an image
Change the 2 in the above code to 1, in the love.mousepressed function.InfamousMakundo wrote:when it is left clicked by the mouse
Edit: has been fixed.
![Awww :3](./images/smilies/ms-three.png)
Last edited by zorg on Mon Aug 29, 2016 3:52 pm, edited 1 time in total.
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
![Awww :3](./images/smilies/ms-three.png)
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: How to make a clicked image (button) draw an image
Oh, you're right, for some reason I read that as right click ![Razz :P](./images/smilies/ms-razz.png)
Fixed it, thanks
![Razz :P](./images/smilies/ms-razz.png)
Fixed it, thanks
-
- Party member
- Posts: 234
- Joined: Mon Aug 29, 2016 8:51 am
Re: How to make a clicked image (button) draw an image
So that's how you create instances...
- zorg
- Party member
- Posts: 3449
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to make a clicked image (button) draw an image
No, the example code was just simple encapsulation. I can't see anything related to instances in it.KayleMaster wrote:So that's how you create instances...
Also, please don't derail threads. If you want to ask stuff, go to the irc.
![Awww :3](./images/smilies/ms-three.png)
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
![Awww :3](./images/smilies/ms-three.png)
-
- Prole
- Posts: 3
- Joined: Sun Aug 28, 2016 3:54 am
Re: How to make a clicked image (button) draw an image
I changed this toHugoBDesigner wrote: if myButton.clicked then
Code: Select all
if click then
toHugoBDesigner wrote:button.clicked = true
Code: Select all
click = true
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: How to make a clicked image (button) draw an image
Glad I could help ![Awww :3](./images/smilies/ms-three.png)
I suggest you add "[SOLVED]" to your title, so other people with similar questions can find this more easily![Wink ;)](./images/smilies/ms-wink.png)
![Awww :3](./images/smilies/ms-three.png)
I suggest you add "[SOLVED]" to your title, so other people with similar questions can find this more easily
![Wink ;)](./images/smilies/ms-wink.png)
Who is online
Users browsing this forum: Google [Bot], Imnotaplayer and 1 guest