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 / Clarification on GetSpriteHitTest()

Author
Message
Golelorn
1
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 13th Feb 2018 01:45 Edited at: 13th Feb 2018 02:07
Either this is not working as intended or I am misunderstanding the instructions per the help file: https://www.appgamekit.com/documentation/Reference/Sprite/GetSpriteHitTest.htm

It should return 1 if I am within the boundaries despite any other sprite. It is only returning 1 if its the only sprite within the boundaries. Even moving this to depth of 0, with the other sprite the default of 10, does not give it precedence. Which according to the help file should not even need to happen.

I don't get it, because I have other sprites that I use gethitspritetest, and there are zero issues. This one.... only works if I click on the part that doesn't conflict. Any suggestions?

I have to click the bottom 50% of the backpack or it doesn't work


This works.. even though its lower depth and the same exact gethitspritetest...


edit: The close button takes up the top half of the backpack icon.

I want to include examples of overlapping sprites that work:



I have zero problems using getspritehittest with these even though they are overlapping... urrrgh.. really frustrated with this one instance not working.

Attachments

Login to view attachments
IronManhood
3
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 13th Feb 2018 09:07 Edited at: 13th Feb 2018 09:07
Quote: "Uses the shape assigned to it from SetSpriteShape. If no shape is set it uses the sprite width and height as a box shape.

If you are testing a mouse or touch coordinate, remember to convert it to world coordinates using ScreenToWorldX and ScreenToWorldY."


Did you mess with sprite shapes and did you convert the pointer position to world coordinates?
Golelorn
1
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 13th Feb 2018 15:07
Everything is the same as every other sprite. And when I do not load the close sprite sprite it works properly. Somehow the close sprite is getting in the way.
PSY
Valued Member
2
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 14th Feb 2018 07:15
Can you upload the close sprite?


PSY LABS Games
Coders don't die, they just gosub without return
Bengismo
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 14th Feb 2018 09:03 Edited at: 14th Feb 2018 09:04
Are you setting the Close sprite to not visible but still leaving it active?

Have you used SetSpriteShape or SetSpriteShapeBox anywhere on the backpack sprite??

You could use GetSpriteHitCategory or GetSpriteHitGroup and ensure they are in different groups ?

Is your screen currently offset?? and are you converting screen coordinates to world coordinates?

Without some sample code people will find it very difficult to help you with this.
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 16th Feb 2018 18:03
I think the sprite is hitting the transparent area of your (other) sprite, instead of using the actual pixels for detecting your sprite.

Use SetSpriteShape( iSpriteIndex, shape ) and set it to '3' as shape for it to use polygon collision. Also keep in mind that a pixel with an alpha of 128 already counts as a visible pixel, so sprites with transparent but not so clean areas might not have a polygonal hitbox the way you intend depending on the true alpha value.

Keep in mind the default 'box' shape every sprite is assigned automatically fully ignores visible or invisible pixels on a sprite and simply uses the total size of the sprite. I also believe it will use square boxes, but I might be wrong.

Anyway, I'd use the SetSpriteShape function whenever sprites are overlapping with default hit boxes. If you need to detect sprites underneath others, I'd use the groups/categories as Bengismo said already.

Login to post a reply

Server time is: 2018-09-20 09:30:32
Your offset time is: 2018-09-20 09:30:32