I'm developing a new game in PB which uses a table of card slots, so that when you have selected a card to place, you can then click on a card slot to move that card there. I'm simply using image placement on an image window. No 2D or 3D commands.
The problem is there are 100 possible rectangles where the player can place the selected card. They are not in a grid. I need to know what method is the best for having the application check the mouse click so as to determine the location to place the selected card?
Should I use a hundred buttons, or an array of rectangle coordinates to compare the current mouseclick, or some other method? I don't want there to be a delay between the mouseclick and highlighting the selected rectangle (with my drawing routine).
Whats the best way to check mouseclick locations in window
-
- User
- Posts: 10
- Joined: Mon Oct 07, 2024 9:15 am
Re: Whats the best way to check mouseclick locations in window
With today's GHz processors, 100 is a small number, so I would guess that it is not a problem (and simple) to test the mouseclick coordinates against an array of rectangle coordinates. Of course that can be made more sophisticated, but a simple loop over all 100 possibilities is not unreasonable. I would suggest doing that at first - it could always be optimized later, but I doubt that will be necessary. If you do the four tests for each rectangle (against its coordinates Xmin, Xmax, Ymin, Ymax) separately instead of in one IF statement then it will take much less than 400 comparisons on average, because often the first test will fail, or the second, etc. Plus there's another factor of 2 in your favor because on average you'll only have to test ~50 rectangles before finding the right one. So maybe 60 or 70 comparisons on average instead of 400.
Re: Whats the best way to check mouseclick locations in window
One CanvasGadget and an array of Type rect with for:next run ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Whats the best way to check mouseclick locations in window
OK I'll first try a loop to test for the mouseclick within rects.
I can probly optimize it by deductive testing, such as "is mouseX greater than firstrowX?" and winnow it down that way.
Thanks for your suggestions guys
I can probly optimize it by deductive testing, such as "is mouseX greater than firstrowX?" and winnow it down that way.
Thanks for your suggestions guys
Re: Whats the best way to check mouseclick locations in window
A hundred rectangle check is so quick, You won't need optimization.