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 Studio Chat / [SOLVED] How can I click on a sprite through the transparency of another sprite

Author
Message
Orion5
3
Years of Service
User Offline
Joined: 6th Jun 2020
Location: SPAIN
Posted: 10th Jun 2020 14:03
Hi, Can anyone tell me please how I can click (Pointer) on a sprite behind another sprite that has a transparent section. Eg A sprite has a transparent hole in it, the sprites depth is say 100. Another sprite is at a depth of say 200 and can be seen through the hole of the first sprite. I want to click on the second sprite, through the hole in the first sprite. Currently all I get returned is the first sprites ID.

Thank you Guru's

The author of this post has marked a post as an answer.

Go to answer

TamBam
12
Years of Service
User Offline
Joined: 29th Nov 2011
Location: India
Posted: 10th Jun 2020 19:18
when 1st sprite return its id that time change those sprite depths but set transparency same then your desire sprite come up and it can be use as you want . May be some one can give better solution -)
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 10th Jun 2020 19:30 Edited at: 10th Jun 2020 19:30
Maybe detect the pixel data of the picked sprite?
Regards Sph!nx
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Jun 2020 01:40
You could set a sprite shape for each sprite
Parry
AGK Developer
14
Years of Service
User Offline
Joined: 16th Dec 2009
Location: Swampstone
Posted: 12th Jun 2020 13:59
Place the sprites you want to be able to click in another sprite group. Actually I done this and I believe I placed the sprites I don't want to be clickable in another group.

Look into these commands:

SetSpriteGroup
GetSpriteHitGroup


Good luck
Parry
Counterparry
DarkDIRE RPG a roguelike game build with AppGameKit Tier 2
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 12th Jun 2020 14:10 Edited at: 12th Jun 2020 14:12
You can use sprite groups or sprite categories for this. This means you can pick sprites underneath others easily.

You can also use these (sprite groups and spite categories)to make a function that gives you a depth ordered list (array) of all the sprites under an x,y coord.

Ive a function thst checks the pixel transparency of the top sprite and if its below a threshold then try the sprite behind it and so on... This allows you to pick a sprite based on pixel alpha colour at an x,y coordinate.
Orion5
3
Years of Service
User Offline
Joined: 6th Jun 2020
Location: SPAIN
Posted: 15th Jun 2020 10:40 Edited at: 15th Jun 2020 11:00
Hi everyone, thanks for the responses. Still having trouble guys! I have set different groups for the top sprite and the sprites behind the top sprite which I can see through the transparency of the top one. When I click on the transparent area of the top sprite all I get returned is the top sprites Group. I think Bengismo has the answer but need a little help with the code to test lower sprite Depths?

Ta muchly guys. (Producing a Digital Signage Solution which is nearly there so will show demo when this is fixed)
Bengismo
6
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 15th Jun 2020 12:00 Edited at: 15th Jun 2020 15:23
EDIT: Removed un-required solution

Attachments

Login to view attachments
Orion5
3
Years of Service
User Offline
Joined: 6th Jun 2020
Location: SPAIN
Posted: 15th Jun 2020 14:59
This post has been marked by the post author as the answer.
Many thanks again! I have manage to get the result I need by using GetSpriteHitTest returning a 1 if the pointer is over the sprite being tested. As the sprites I need to detect are in an array it is a relatively simple matter of checking each sprite in the array and hey ho I can find the Sprite ID from the array, works great so far as my detection need is fairly simply.

Project moving on nicely, see screenshot...

Many thanks

oliverwright
3
Years of Service
User Offline
Joined: 16th Jun 2020
Location:
Posted: 16th Jun 2020 13:59
good

Login to post a reply

Server time is: 2024-03-29 06:41:11
Your offset time is: 2024-03-29 06:41:11