Efficient Mouse Interaction and Event Handling for Objects

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.
Athrikesha
Prole
Posts: 7
Joined: Mon Sep 18, 2023 6:46 pm
Contact:

Re: Efficient Mouse Interaction and Event Handling for Objects

Post by Athrikesha »

BrotSagtMist wrote: Tue Sep 19, 2023 12:38 pm There are a few other methods, but they are all highly situation dependent.
This if its in range check is the best option to use usually.
So whats wrong with it? Where is your complain?
This is easy to write and fast to execute and there is nothing to improve.
Unless you have to deal with say a few thousand images at once where instead you can map the screen to a lookup table.
A lookup table has almost zero check time but a high creation cost. So there is that.
Oh, i see. I do commonly use the tables for storing images and its position. How can I create and use a lookup table (dictionary)? Can you provide a code example for implementing and utilizing a lookup table in this context?
User avatar
pgimeno
Party member
Posts: 3593
Joined: Sun Oct 18, 2015 2:58 pm

Re: Efficient Mouse Interaction and Event Handling for Objects

Post by pgimeno »

Athrikesha wrote: Fri Sep 22, 2023 8:38 am No this is still quite buggy, unless i am mistaken. Moreover i think that it is slower, than one might expect. One improvement would be to lock the active rectangle and release the lock only when mouse is released, but i dont know. Slower in the sense, the speed when we drag a rectangle is dubious.
There is no way around having lag when dragging something.

viewtopic.php?p=195509#p195509
Athrikesha
Prole
Posts: 7
Joined: Mon Sep 18, 2023 6:46 pm
Contact:

Re: Efficient Mouse Interaction and Event Handling for Objects

Post by Athrikesha »

One other thing, that is relatively off-topic.

I have seen browsers rendering css more effectively. Say for instance even the hover function looks like it relatively effortless. Does this mean lua over love2d, has an inherent shortcoming to implement such sort of. Or am i so unaware of some fundamentals. I explect a non out of box solution to place, and track images on screen.

https://drive.google.com/file/d/1-jMGAX ... sp=sharing

There are two aspects to my question
1. Easy coding - manageability of multiple images, with less fuss on images and their position tracking.
2. Efficiency - i can implement a solution where i onload a few images within a table. And then proceed with iterating though the table for image/object that matches the mouse x,y. But wont it slow down and induce a drag?.

What i expect as a solution (This could sound a bit silly but be with me on this):
a library like function that handles a lot of images and tracks their position and implement best means (algorithm) for detecting the images that are active. cost wise and manageability wise.

Tanks
User avatar
Bobble68
Party member
Posts: 161
Joined: Wed Nov 30, 2022 9:16 pm
Contact:

Re: Efficient Mouse Interaction and Event Handling for Objects

Post by Bobble68 »

Athrikesha wrote: Fri Sep 22, 2023 1:01 pm One other thing, that is relatively off-topic.

I have seen browsers rendering css more effectively. Say for instance even the hover function looks like it relatively effortless. Does this mean lua over love2d, has an inherent shortcoming to implement such sort of. Or am i so unaware of some fundamentals. I explect a non out of box solution to place, and track images on screen.

https://drive.google.com/file/d/1-jMGAX ... sp=sharing

There are two aspects to my question
1. Easy coding - manageability of multiple images, with less fuss on images and their position tracking.
2. Efficiency - i can implement a solution where i onload a few images within a table. And then proceed with iterating though the table for image/object that matches the mouse x,y. But wont it slow down and induce a drag?.

What i expect as a solution (This could sound a bit silly but be with me on this):
a library like function that handles a lot of images and tracks their position and implement best means (algorithm) for detecting the images that are active. cost wise and manageability wise.

Tanks
As far as I know, Love doesn't have anything to help with this, probably because this isn't a difficult problem to solve, nor is it particularly slow. (Brot will probably complain) but my instinctual response for making it easy to make an image/button class.

As for efficiency, it doesn't get much more efficient than iterating through a table and checking if the mouse is within a rectangle - I think if you implemented it yourself, you would find that it also looks effortless. As long as the calculation can be done in less time than it takes to render to the screen, you generally won't notice anything. If you really want to make it more efficient, then I guess you could make it so that it only does the check when either the mouse moves, or the one of the image's position changes, though to me that sounds like overkill.

tldr: Don't worry too much about efficiency until it's actually a problem
Dragon
Athrikesha
Prole
Posts: 7
Joined: Mon Sep 18, 2023 6:46 pm
Contact:

Re: Efficient Mouse Interaction and Event Handling for Objects

Post by Athrikesha »

Bobble68 wrote: Sat Sep 23, 2023 8:17 pm
Athrikesha wrote: Fri Sep 22, 2023 1:01 pm One other thing, that is relatively off-topic.

I have seen browsers rendering css more effectively. Say for instance even the hover function looks like it relatively effortless. Does this mean lua over love2d, has an inherent shortcoming to implement such sort of. Or am i so unaware of some fundamentals. I explect a non out of box solution to place, and track images on screen.

https://drive.google.com/file/d/1-jMGAX ... sp=sharing

There are two aspects to my question
1. Easy coding - manageability of multiple images, with less fuss on images and their position tracking.
2. Efficiency - i can implement a solution where i onload a few images within a table. And then proceed with iterating though the table for image/object that matches the mouse x,y. But wont it slow down and induce a drag?.

What i expect as a solution (This could sound a bit silly but be with me on this):
a library like function that handles a lot of images and tracks their position and implement best means (algorithm) for detecting the images that are active. cost wise and manageability wise.

Tanks
As far as I know, Love doesn't have anything to help with this, probably because this isn't a difficult problem to solve, nor is it particularly slow. (Brot will probably complain) but my instinctual response for making it easy to make an image/button class.

As for efficiency, it doesn't get much more efficient than iterating through a table and checking if the mouse is within a rectangle - I think if you implemented it yourself, you would find that it also looks effortless. As long as the calculation can be done in less time than it takes to render to the screen, you generally won't notice anything. If you really want to make it more efficient, then I guess you could make it so that it only does the check when either the mouse moves, or the one of the image's position changes, though to me that sounds like overkill.

tldr: Don't worry too much about efficiency until it's actually a problem
yeah, this needs to be said, thanks
Post Reply

Who is online

Users browsing this forum: Google [Bot], veethree and 1 guest