English Detecting the player cursor on an inaccurate image

2 replies
Goto Page
To the start Previous 1 Next To the start
Up
The Dark Shadow
User
Offline Off
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.
30.07.20 12:42:39 am
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
30.07.20 09:25:26 am
Up
The Dark Shadow
User
Offline Off
@user DC: Alright, I'm gonna do that, Thanks sir
To the start Previous 1 Next To the start