Quote: "gravity variable that decreases each loop. This gravity variable is then added to the player's current Y position."
Quote: "gravity should be timesed by 0.9 or around that
it is more effective than taking away."
Wow wow guys.
Gravity is a force. A force is not added to a position just like that! (It might work, but the naming is incorrect). That force causes an
acceleration. You can calculate the gravity force, by multiplying the object's mass with the strength of the earth's gravity g = 9.81N/kg (F = m*g).
This gravity has an effect on a free body's
acceleration. The acceleration can be calculated using Newton's 2nd law F = m*a, which leads to the equation
a = -g.
In general, Newton's 2nd law leads to very difficult differential equations which are hard to solve, or not to solve at all. But computers use an easy approximation technique which basically comes down to this:
yAcceleration# = -9.81
ySpeed# = ySpeed# + yAcceleration# * timeElapsed#
yPosition# = yPosition# + ySpeed# * timeElapsed#
Sometimes timeElapsed# (seconds) is taken 1.0, and the gravity is scaled down for compensating that factor (in that case, yAcceleration equals the acceleration in pixels/loop). The equations are wrong then, but still a pretty good approximation in games.
yAcceleration# = -9.81 / Factor#
ySpeed# = ySpeed# + yAcceleration#
yPosition# = yPosition# + ySpeed#
A big difference between those two, is that the first equations are better suited for timer based movement, whereas the second ones are usually chosen for their simplicity.
I recommend using the second version for starters.
Cheers!
Sven B
Sorry if I'm giving too much information. But learning wrong things can make it harder later on.