I’m currently trying to make a basic platformer with XNA and I’m wondering how to create a “jumping effect.” I currently have basic keyboard input which allows for sideways movement, but I would like my sprite to slowly progress into a jump rather than instantly teleporting there (right now I have something like Rectangle.Y += 40 every time I jump, making the sprite instantly appear there). Does anyone have any insight?
Share
I’m not totally across how to implement this in XNA/C#, but in Flash games I’ve made I just added a vertical velocity property. I’ll try write everything as C# as I can..
Example; create the velocity property:
Vertical velocity should be constantly reduced (by gravity). Set up a gravity property somewhere accessible from your player:
And in your
update()method for the player, increment theverticalVelocitybyGravity. Also increment theYposition of your player by theverticalVelocity. This will simulate falling:When you hit a surface, the velocity should be reset to 0.
And finally, to jump, simply subtract a given value from
verticalVelocity: