Forum

> > CS2D > Scripts > Detecting the player cursor on an inaccurate image
Forums overviewCS2D overview Scripts overviewLog in to reply

English Detecting the player cursor on an inaccurate image

2 replies
To the start Previous 1 Next To the start

old Detecting the player cursor on an inaccurate image

The Dark Shadow
User Off Offline

Quote
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.

old Re: Detecting the player cursor on an inaccurate image

DC
Admin Off Offline

Quote
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 cs2d lua cmd 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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview