Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Getting transparency for individual pixels on a sprite

Author
Message
Laughing Coyote Software
5
Years of Service
User Offline
Joined: 30th Jun 2018
Playing: Pillars of Eternity 2
Posted: 28th Dec 2021 21:09
In Warlordocracy, the player can click on objects to interact with them. Right now I just get the sprite size and see if the cursor is there, but I would love a way to test if the cursor is currently over a transparent pixel in the sprite to make it more accurate. Is there any way to do this in AppGameKit?

Steam Demo Link
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Dec 2021 13:45 Edited at: 29th Dec 2021 13:48
you're asking for pixel-perfect accuracy which, in my opinion, is overkill and would be a serious performance hit.

that being said, and keeping your current method as a base, once the sprite is detected, you would have to figure out which image (frame, if animated?) it's using, calculate which pixel in that image the pointer is currently over, turn that pixel into a memblock and read its alpha value there to achieve what you're looking for.

instead, consider using SetSpriteShape() commands. ideally SetSpriteShapeBox() which is the fastest of the bunch. set the box size (and offset, where appropriate, and/or rotation) to get closer to the accuracy you're looking for. If a circle would be more accurate for a given sprite, then SetSpriteShapeCircle() would be the next-fastest, i believe, followed by SetSpriteShapePolygon() for improved accuracy.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 29th Dec 2021 14:21
a little more toward "pixel perfect": you could do some prep work for the sprites and keep the memblocks on-hand for quick "look up" vs determining image and creating the memblocks "live". short on time, now, but THIS might help explain the theory.

finally, and speaking of overkill, many wouldn't consider using Box2D for something like this because you're really not needing "physics" per se but with the additional sprite shapes that the system allows and the multi-thread usage that Box2D affords, you should see a performance boost with while increasing "sprite shape" accuracy overall.
Laughing Coyote Software
5
Years of Service
User Offline
Joined: 30th Jun 2018
Playing: Pillars of Eternity 2
Posted: 31st Dec 2021 06:44
Thanks man, I just discovered a more urgent problem that's gonna give me an aneurism. I'll get back soon.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 31st Dec 2021 11:22
You're better off using hitboxes if you're just detecting collisions.

Login to post a reply

Server time is: 2024-04-23 19:41:20
Your offset time is: 2024-04-23 19:41:20