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.

Years of Service
User Offline
Joined: 2nd May 2012
Posted: 23rd Aug 2017 16:38
I am making a basic 2d scrolling game and I am having a hard time with the gravity. I am using a concept of where in the main loop, the y-position of the sprite automatically increases until the sprite collides with another sprite. When the collision checks one sprite it seems to work. When I try to do a check of multiple floor sprites, it doesn't create the gravity.

sprite 11 = the human controlled player
sprites 5001-5500 = possible floor sprites
ypos(1) = y position for the human controlled player

Even this way isn't working:

When I do it like this, he falls through it

Help please?!? ps embarrased because I solved this before but I have some time now and I will back up all solutions and never let up this time!!!!
- Infinity is Simplicity -
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 24th Aug 2017 05:13
need to see more of your code really it could be a number of things
A child's dream never dies.

Bio Fox
Years of Service
User Offline
Joined: 11th Nov 2004
Location: The BioFox Bunker
Posted: 16th Sep 2017 14:37
I recently finished a 2d platformer (see here: and had good luck with gravity. You're thinking about it in the right way, but let show you how i did it.

It's very simple, but I use multiple sprites. Basically, consider that you have the player sprite, and then a sprite for each direction surrounding the sprite (see attached image). The bottom sprite will be used to detect collision with the floor. This frees up detection for walls and ceilings for the "west", "east", and "north" sprites. See the native sprite collision command can only detect collision with one sprite at a time. Make sure you're not trying to detect multiple sprites with a single sprite because it won't work, at least not with sprite collision(x,x).

Also, it's important to consider that my character is always on the same position on the screen and I move the background with player_y#. I also move all the collision sprites used for platforms so they stay relative to the background. This is all a high level explanation, but you're going in the right direction. Try to boil your code down to just character movement, gravity, and sprite detection and post it here! That will help us help you better. Good luck!
BioFox Games


Login to view attachments

Login to post a reply

Server time is: 2023-09-28 06:17:52
Your offset time is: 2023-09-28 06:17:52