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 / Strange pixel anomaly

Author
Message
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 27th Nov 2018 18:32
I have been trying to build a simple platformer game. I have a strange behavior in drawing where there sometimes is a visible gap between player sprite and platform and sometimes not. I attached screenshot showing the issue.

I have been trying to debug what impact the decimals in sprite position have to this effect but have not found any correlation: the gap can be visible or then not with more or less same same decimals in y-position. I also tried if SetViewOffset has impact on this but the effect is the same when not scrolling the view and when scrolling is enabled.

Any idea what is causing this and is there a way to get rid of this anomaly somehow?

Attachments

Login to view attachments
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 27th Nov 2018 18:34
how are you handling checking the sprite is on the platform or not? i.e. collision shapes? physics? ray casting?
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 27th Nov 2018 18:41
With collision shapes. No physics involved. I check against all block sprites which are stored in array. The code is likely not most effective at the moment as I have been trying to get this thing to work



And the function PlaceMeeting:



signf function returns either -1,0,1 depending whether given value is negative, zero or positive.
puzzler2018
User Banned
Posted: 27th Nov 2018 18:43 Edited at: 27th Nov 2018 18:44
You say that your using Decimals - could you perhaps use floats?

Do you have a sample peice of code showing this fault and can have a better solution

EDIT - you read my mind lol - please bear with us for a remedy
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 27th Nov 2018 19:07
Also to note that I have the screen (window size) set to 1280x720 and virtual resolution set to 640x360. The sprite and block size is 24x24.

I also tested to not use the virtual resolution but the effect is the same.

But just noted that there's something fishy somewhere as the system reports a collision when trying to move between a hole with height of exactly 1 block (24 pixels) even though sprites are not colliding (attached an image of this).

Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 27th Nov 2018 19:09 Edited at: 27th Nov 2018 19:11
For some reason your code was a little bit exhausting for me

Try this way



hope it doesnt mess things up for you - but i find this way works just as well and a little bit shorter in code
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 27th Nov 2018 19:18
Thx! I’ll try it in the morning!
puzzler2018
User Banned
Posted: 27th Nov 2018 19:19
Hope this helps



Sorry to redesign your existing though...
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 27th Nov 2018 20:16
ok it is because you're moving in 1 increments (integers) during the collision checks but you could start less than 1 above the platform due to falling / moving in floats.
if puzzler's solution doesn't help you likely want to check when the collision happens and then move in smaller amounts till it is more precise to where you want it (or use the physics and let it work out the point of impact).

something like this (press space to reset the cube to a new random height to fall from)
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 28th Nov 2018 11:17 Edited at: 28th Nov 2018 12:11
Thx guys for your support!!

Indeed the fact smallg pointed out seems to be the reason. If I add the rounding to y-position after collision the player aligns perfectly with the grid and tiles.



However this leads to a problem with horizontal collision checking as the system thinks player collides with tiles directly below it and therefore can't move horizontally. For example player is located on the first possible row with y-coordinate being 0 with ground below starting at y-coordinate of 24 (see the attached picture). Could it be that the GetSpriteCollision-function reports collision when the shapes are next to each other but not overlapping (the y-coordinate of the player box shape in the example is from 0 to 23 and for the ground tiles below the player 24-47).

Lifting up the player by one pixel (decreasing the y-coordinate by 1) for horizontal collision checking fixes this behavior. So the workaround could be to do that and decrease the height of the player collision shape by 1 pixel. However somehow I don't get the logic how the GetSpriteCollision reports collisions...

I don't know if the physics based collision checking could work better / more easily?

Attachments

Login to view attachments
w0rm
6
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 28th Nov 2018 17:50 Edited at: 28th Nov 2018 17:51
Hmm, somehow this seems to be related to on how the default collision shape works.

Adding the following when creating player sprite seems to fix the odd behavior. After this there's no more this mysterious gap appearing randomly with the original code and player is also able to move between holes of size 1 block (24x24 pixels).



If I change the above to



I get exactly the same strange behavior as without it: random gap between player and ground, not able to run through holes of size 24x24 pixels (exactly the size of the player sprite and block sprite).

However I find it hard to believe that the default shape logic would be off by 1 pixel?
puzzler2018
User Banned
Posted: 28th Nov 2018 17:56 Edited at: 28th Nov 2018 17:56
Perhaps aybe its due to having it starting at 0

0-23 = 24 pixels
0-24 = 25 pixels

Maybe

Login to post a reply

Server time is: 2024-11-23 12:53:15
Your offset time is: 2024-11-23 12:53:15