## what was there when I pressed the button?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
needhelp911
Prole
Posts: 3
Joined: Sun Jun 17, 2018 2:33 am

### what was there when I pressed the button?

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

uiblob
Prole
Posts: 7
Joined: Sun Jun 10, 2018 8:06 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.

PGUp
Citizen
Posts: 78
Joined: Fri Apr 21, 2017 9:17 am

### 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.
-

KayleMaster
Party member
Posts: 198
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:

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

Where image_table would look like:

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}
}


needhelp911
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], Exabot [Bot] and 5 guests