What is the best way to create a bunch of images that do something when clicked?

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.
Post Reply
Taycamgame
Prole
Posts: 4
Joined: Sun Jun 14, 2020 5:54 pm

What is the best way to create a bunch of images that do something when clicked?

Post by Taycamgame »

Basically, I'm making a title screen menu. I'm using images for the menu options (e.g. start game, options).

What's the best / most efficient way to run a piece of code after clicking on these images? One idea is that I just write the same code multiple times to have different image coordinates and run different code for each one. However, I have a feeling it would that using classes in some way would make it much more efficient, but I don't know how to use them (both in general and in this context).

Thanks :)
User avatar
pgimeno
Party member
Posts: 3594
Joined: Sun Oct 18, 2015 2:58 pm

Re: What is the best way to create a bunch of images that do something when clicked?

Post by pgimeno »

What you want is a (very barebones) GUI. Basically, clickable image buttons.

Your code needs to be able to find the position and size of each image, then when the mouse button goes down, go through all of them and check whether the mouse is inside one.

Traditionally, GUIs have tables with the position and size of each element in the GUI, and query all of them every time the mouse is pressed. You could do that too, have a table for each image and then a container table with all the other tables.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 8 guests