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.
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: 3465
- 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.
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.
- 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
Fixed it, thanks
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: 3465
- 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. (whereby you'll be probably told to read the PIL anyway.)
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.
-
- 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
I suggest you add "[SOLVED]" to your title, so other people with similar questions can find this more easily
I suggest you add "[SOLVED]" to your title, so other people with similar questions can find this more easily
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 8 guests