I'm developing game in marmalade sdk in c++. I have player in the area.and I wanna make him jump when i pressed a button.When I use this player.moveUp(5px); it just go up 5px, but he has to fall down back. so that when i use these: player.moveUp(5px); and player.movedown(5px); it do nothing.Because the fps is 30 and it's performing so fast. how i can fix that?
Jumping is an operation that you need to have take effect over time, not an instantaneous modification to the player location. To make a realistic jump, you're going to want to take into account:
- Gravity (an acceleration downward)
- Player height (i.e., y coordinate)
The relationship between these will be something like this:
pos_y = pos_y + (velocity_y * time_difference) + (gravity_y * (time_difference ^ 2) / 2) velocity_y = velocity_y + (acceleration_y * time_difference)
(That formula is taken from an answer on impulsed jumping.)
The gravity is a constant acceleration downard, which is constantly modifying the velocity. So the velocity starts out going up, and gets pulled progressively downward. The change in time (delta) is used to determine how far along the process we are.