4 ms·
Even with Google, it's a difficult problem[1]. What if you have multiple items on the same tile? What if one of them is one pixel wide (e.g. a wall)? What if so
by YesBox 2y ago
Even with Google, it's a difficult problem[1]. What if you have multiple items on the same tile? What if one of them is one pixel wide (e.g. a wall)? What if something in front of that tile is tall enough to block the view? What if you need pixel perfect collision?
My first solution (before the buildings in my game had multiple floors) was to take the ISO mouse position, grab a list of items within a cone spreading towards the screen, then:
1.) Loop through each item
2.) Create a sprite of the item (so I have direct access to RGBA info)
3.) Convert mouse coords to sprite coords
4.) Check if I'm hitting a pixel (i.e. alpha > 0)
5.) Keep track of this item
6.) Update if an item closer to the bottom of the screen (i.e. closer to camera) gets a hit
Once I added building height, this became impractical (too many items to loop through, sprite creation is CPU intensive).
New solution is to assign a 24 byte UUID to each item, convert that to RGB, draw it to the screen (invisible to the user), and then return a tiny texture every frame from the GPU at the mouse position. If the color in the texture is not black, then convert RGB back into the UUID.
PS: If you know how to draw so that alpha replaces existing alpha (instead of blending), please let me know so I can have 32 byte UUIDs!
[1] Source: I'm developing Metropolis 1998 https://store.steampowered.com/app/2287430/Metropolis_1998/ https://store.steampowered.com/app/2287430/Metropolis_1998/
- mrec 2y agoHeh. I remember doing your first solution for an Eye of the Beholder-style FPV engine back on the Amiga circa 1994. This was using existing blitter mask bitplanes so there was no sprite creation, everything was very fast (assembly). Can't remember whether I did culling based on bounding boxes first. I also remember being quite chuffed about coming up with a "novel" approach using dithered planar masks to offset colours into palette ranges for not-too-blocky lighting. Then Quake came out. You forget just how siloed we all were before the Internet took off; every wheel imaginable must have been reinvented so many times...