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 / GetSpriteHitGroup() adding 1 pixel to right & bottom?

Author
Message
Nieb
9
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 9th Oct 2020 20:00
GetSpriteHitGroup() appears to be adding 1 pixel to the bottom & right of sprites tested.
Test project attached.

Attachments

Login to view attachments
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Oct 2020 20:54 Edited at: 9th Oct 2020 20:57
Nieb,

I'm finding that if you test with Floats as returned by GetRawMouseX/Y(), things seem to be working as intended. IE:


Original Loop for reference to others that haven't DL'd the OPs project:
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]
Nieb
9
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 9th Oct 2020 21:12 Edited at: 9th Oct 2020 21:13
I'm working with a pixel art game, there are no floats.
GetSpriteHit() has same issue

I've made my own AABB function to use.
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 9th Oct 2020 23:24 Edited at: 9th Oct 2020 23:45
Try this:



It's not a bug, you just did not define the specific sprite shapes that are responsible for the actual hit test. You can rem out the logic for the 678 group and it works fine, I just included both, to demonstrate that it works well for both sprite groups.

EDIT: However, in the case you mean it is a bug in the sense of AppGameKit using the sprite width and height as the box shape for the hit test when no sprite shape is defined, then I see your point. It does appear to be one pixel too much. Knowing AppGameKit logic at times 10/4=2, I am not suprised. Personally I would not trust AppGameKit to make the sprite shapes for me. In my experience, AppGameKit knows very well what to do as long as the user specifies exactly what AppGameKit must do.
????????
Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 10th Oct 2020 20:07 Edited at: 10th Oct 2020 20:24
UPDATE to the above:

I played around a bit more with this and for some reason it didn't work as the code I posted, one of the sprite groups worked the other didn't quiet work, despite the first time I tested it, it all did work, so I decided to investigate this further and created the following code for you to test this yourself:



The arrow keys move one sprite, the WASD keys move the other and it does appear that there is a certain strange behavour with integers. I have not tried using floats as Virtual Nomad suggested, but this could be part of the solution, however still strange the behaviour. Test it yourself and you will see. I attach a short video recording of the test I did on this and I don't understand the logic of it, so it could be that Nieb has a valid point on this matter, unless someone with more knowledge and experience can clarify this odd behaviour.



ADD: I just tested the float principle and it appears that Virtual Nomad's solution is correct. The reason being is the integer use instead of float. With floats it works perfect. So I guess you will have to figure out the logic to make this work with the integers, how you gonna do that for the pixel game, good luck with that.
????????
Nieb
9
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 11th Oct 2020 18:52 Edited at: 19th Oct 2020 09:33
The red transparent sprite has nothing to do with the bug, I just put it there to show where the bug is occurring with the blue sprite.

I'm no longer using any of the built in sprite hit/collision commands. I've made some of my own AABB collision testing functions:

Lupo4mica37
3
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 11th Oct 2020 19:04
Hi Nieb. I understand that the red sprite was to show the anomaly, but in both cases you will get the same anomaly depending on where the sprite is positioned. Anyway I am glad you solved it yourself. All the best on your pixel art game.
????????

Login to post a reply

Server time is: 2024-03-28 12:22:04
Your offset time is: 2024-03-28 12:22:04