I have to make this game, but I dont know how to make my computer know what image I just clicked.
My game is a puzzel, where as time goes by my images change their actual position with another, the bassically chance their places.
p.s- sprry about my english, I dont speak a lot
what was there when I pressed the button?
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 Jun 17, 2018 2:33 am
Re: what was there when I pressed the button?
Just save the positions of the images, along with the positions of all the edges, and on click search if the click happened between the edges of a picture, if not try the next one etc.
There are better ways than a simple loop for every image but you can optimize later, it works for a prototype.
There are better ways than a simple loop for every image but you can optimize later, it works for a prototype.
Re: what was there when I pressed the button?
Learn how to iterate through table in Lua first
Last edited by PGUp on Sun Jun 17, 2018 1:16 pm, edited 1 time in total.
-
-
- Party member
- Posts: 234
- Joined: Mon Aug 29, 2016 8:51 am
Re: what was there when I pressed the button?
Are your images rectangular? Than it's easy as:
Where image_table would look like:
Code: Select all
function love.mousepressed(x, y, button, istouch)
if button == 1 then -- Left mouse button pressed
for index, image in ipairs(image_table) do
if x > image.x and y > image.y and x < image.x + image.width and y < image.y + image.height then
image.selected = true
end
end
end
end
Code: Select all
image_table = {
{x = 10, y = 20, width = 100, height = 50, selected = false},
{x = 50, y = 4, width = 600, height = 130, selected = false},
{x = 300, y = 80, width = 200, height = 400, selected = false}
}
-
- Prole
- Posts: 3
- Joined: Sun Jun 17, 2018 2:33 am
Re: what was there when I pressed the button?
thanks, i finally get it
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest