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.

Newcomers AppGameKit Corner / Avoid detecting sprite hits using setspritedepth()

Author
Message
Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 29th Jan 2018 02:00
Is there some way to avoid detecting the spritehit when one sprite is behind another? Should I create an array of objects and iterate to check if they are in the front or not?

Here's an example:



I want to avoid the sprite hit detection of the "spt" sprite since its behind another sprite.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jan 2018 02:23
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 29th Jan 2018 08:59
Just use GetSpriteHit() ??

It returns the sprite with the lowest depth so if spt is under lb then the hit test will give lb
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 29th Jan 2018 09:49
Using GetSpriteHit() would probably be you best bet but if you are only using those two sprites you could check to see if the two sprite are colliding.
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 29th Jan 2018 16:47
There are a few ways to do that, and each depends on program's needs.

You could just use getspritehit(), as has been suggested. But then what about when the other sprite needs to be hit? I think it would get very confusing.

Or change the sprite depth. The ones that are inactive need to be moved to the back, and the actives one need to move to the front.

You also may want to try setting states. And include that in the if statement. For instance.. jump_state = 1. Then during jump_state = 0 the sprite can't be selected.

GetSpriteHitTest is checking the screen coords and ignores depth.

Richard_6
7
Years of Service
User Offline
Joined: 3rd Feb 2017
Location:
Posted: 30th Jan 2018 02:39
Yes, using getspritehit() instead of getspritehittest() was enough to make it work. I thought both would find the first sprite under the get pointers, but they behave differently.

Thank you guys!
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 2nd Feb 2018 22:06
It gets worse when you try to add bigger sprites with transparency or stuff that should overlap, but not necessary respond to a mouse click. Honestly, AppGameKit could do with a feature that returns all sprites on a given location or allows you to set flags that allows you to effectively ignore specific sprites.
Correct me when I'm wrong, but I don't think SetSpriteGroup fixes the issue of overlapping screen sprites you don't want to see returned by GetSpriteHit , right?
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 2nd Feb 2018 22:59
Quote: " Honestly, AppGameKit could do with a feature that returns all sprites on a given location"


We already have that...
You can iterate through the sprites and use GetSpriteHitTest() one at a time
or...
You can use GetSpriteHitGroup() or GetSpriteHitCategory() to get sprites of a certain type and filter out any that you dont want.

Quote: "Or allow you to set flags that allows you to effectively ignore specific sprites."

We have that ... SetSpriteCategoryBit() and SetSpriteCategoryBits() and SetSpriteGroup()

Quote: "Correct me when I'm wrong, but I don't think SetSpriteGroup fixes the issue of overlapping screen sprites you don't want to see returned by GetSpriteHit , right?"


You use GetSpriteHitGroup() and it filters out the results you dont want. You can also use GetSpriteHitCategory( categories, x, y ) and it only reports sprites that are in the category you want to collide with. Both work well!

PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 3rd Feb 2018 00:14
@Bengismo: Interesting, thanks a lot. That sounds like a very useful set of commands I wasn't aware of working like that.

The copy & paste nature of the online manual seemed to suggest GetSpriteHitCategory would still return only the sprite with lowest depth. On a second read it looks I misread.

Login to post a reply

Server time is: 2024-11-21 19:54:17
Your offset time is: 2024-11-21 19:54:17