irregular map
BlitzMax Forums/BlitzMax Programming/irregular map
| ||
I need to select a bunch of black images irregularly distributed on a white background; images are randomly scattered so that it is impossible to surround them with a box (otherwise simple box checking would be the solution). In my case boxes would often overlap, so it is difficult to select right box. It would be very time consuming to define irregular polygons around each image and detect one of them. In other words, I need some form of collision detecting on an irregular map, detecting also which image has been selected. Can someone give me hints? |
| ||
If you're feeling daring you could create a 2d array the size of the screen of a type which refers to the image on top of it or null if there are no images. Then when you click you can just look up the image refered to at that point in the array. This would take about 1.2mb of ram for a 640x480 screen (just from the array, plus your types). You will need to init this array when you place down the images at the beginning of course. Alternatively, loop through every image and check whether the mouse cursor is in the image. You can do this by having a special 1x1 image which you collide check on the mouse cursor's location with the image. I don't often use collide image function so I can't remember how to do it properly. This will need to loop through every image each click but won't use as much memory. Unless you have thousands of images it won't even be as slow as you think. I suggest this solution first. Last edited 2011 Last edited 2011 |
| ||
I am going to assume each is a Timage first you can store every image in a list ordered from front to back in it. [pseudocode] item = eachin list check boundingboxcheck(item) check if collision with (item) visible image select image; if required, move to top of list exit loop end check end check next item display list from the last to the first [end pseudocode] you can use a bounding box collision first then use images collided for the final check. the first image that passes the tests is the correct image no further test are required also to display the list in reverse you need to use Tlink Last edited 2011 |
| ||
That's better than my haphazard solution. |
| ||
thank you, a lot of ideas to try |
| ||
I've actually used the 2D array technique that CzarFlavius referred to above in a shipped title. It sounds wasteful at first, but if you think that just one image or texture probably uses about as much memory, it's really not that bad at all. Ultimately, it probably depends whether speed is critical and how many images you're going to have. A few images and non-speed-critical, then something like Jesse's solution is probably best. If it is speed critical (as my need was) and if you have a lot of images on there, that bit of extra memory is a small price to pay. Last edited 2011 |