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.

Dark GDK / Gravity in 2D?

Author
Message
Manga Tiger Boy
15
Years of Service
User Offline
Joined: 24th Aug 2009
Location:
Posted: 22nd Feb 2010 23:31
How can I make gravity in 2D for my platformer? (While you're at it, can you tell me how to do backdrop collsions, plz?)

I'm pretty new to programming; I'm used to TGF2 already having the maths done for me Thanx in advance!

Join the dark side. We have cookies!
How is it going
17
Years of Service
User Offline
Joined: 18th Sep 2007
Location: California
Posted: 23rd Feb 2010 04:29 Edited at: 23rd Feb 2010 04:31
I assume that you have an x and y variable for the position of the sprite
so what you do is while there is no collision with the floor, decrease the y position: --y <- or whatever your variable is called
I usually check what pixel color is in the backdrop to do collision but I'm not sure what the correct way to do this is.
I assume that a lot of people probably use individual spritesd for each "tile" then you can use DarkGDK's sprite collision commands
hope that helps
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 23rd Feb 2010 04:47
To create gravity, you need to increase the Y position of a sprite. The reason for this is that the Coordinate's origin starts in the upper left hand corner of the window, here's the best way to illustrate this.



So to create gravity, you will need to increase a Y value.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
CrazyCoder
14
Years of Service
User Offline
Joined: 30th Mar 2010
Location: Great Britain
Posted: 9th Apr 2010 23:51
For better gravity have variables Y and YSpeed.
Instead of increasing Y, increase YSpeed and then increase Y by YSpeed, so the character accellarates downwards, because the downward force is being continually increased.
With this then you could let the player jump by giving them upward force.
Here is an example:

The ground height (that I have set to 440) will vary depending on the X position if you have platforms.

Login to post a reply

Server time is: 2024-11-19 15:29:14
Your offset time is: 2024-11-19 15:29:14