CS2D
Scripts
Detecting the player cursor on an inaccurate image
Detecting the player cursor on an inaccurate image
2 replies How to detect if the player cursor is exactly on an inaccurate/not fit image in pixel, Skipping transparent pixels? For example a circle, a rectangle, a star, or whatever. Not possible? Would it be hard? Would it be laggy while each positions/pixels of the image would be calculated? What's the most decent way to get that?
Would be appreciated as well. DC Admin
Offline
CS2D doesn't offer any utility methods for something like that. It's probably possible but not easy.
You would somehow have to read and store the information which pixels are transparent. I can only think of two ways to do so:
write a PNG reader in Lua or use an existing one e.g.: https://github.com/Didericis/png-lua and use it to read, extract and store the alpha information
or do the PNG reading and processing beforehand with other software and somehow store the information in a format which can be read in Lua easily (or directly export the information as Lua table)
Afterwards you can use
player mousemapx and mousemapy and the position of the Lua image to calculate the cursor position in the image and then - if the cursor hovers the image - check against your data if there is transparent pixel at that position or not. @
DC: Alright, I'm gonna do that, Thanks sir