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.

2D All the way! / Can't Get Gravity to work, quite

Years of Service
User Offline
Joined: 20th Jun 2011
Posted: 23rd Jun 2011 11:26
So here's the code I'm working on. At the moment jumping and suck work. I'm trying to figure out the easiest way to make it to add more floors above and below and have the character fall down to these levels. Any hints would be most appreciated.

Years of Service
User Offline
Joined: 15th Oct 2010
Posted: 28th Jun 2011 19:42
Hey brah,
For some reason, opening your code snippet closes my browser window. But anyway...gravity is a pain for 2D games IMO. The way I set it up is with a subroutine that goes through a loop, checking for any platforms. It then compares the player's y coordinate and tries to match it with the platform's y coordinate, then does the same for x coordinates. If the player infringes any platform boundaries, the loop is exited and player.falling = false. A separate subroutine checks if player.falling = true; if it is, the player's y coordinate is increased.
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 29th Jun 2011 15:14
Yes, you can loop through all sprites and compare them to the players Y position:

Or you can check collision with any sprite with 1 command:

if sprite collision(player_sprite,0) then do stuff


Login to post a reply

Server time is: 2024-03-01 16:32:49
Your offset time is: 2024-03-01 16:32:49