2d game physics?

前端 未结 11 515
难免孤独
难免孤独 2020-12-28 19:53

Can anyone point me to a library for 2D game physics, etc for programming gravity, jumping actions, etc for a 2d platform/sidescrolling game ? Or could you suggest some algo

相关标签:
11条回答
  • 2020-12-28 20:44

    If all you need is gravity, you can program that yourself in 5 minutes. Free-falling objects accelerate down at 9.8 meters per second per second - that is, an object's downward velocity increases by 9.8 meters per second of free-fall. For a game, you'll want to divide that 9.8 by whatever your frame rate is. For jumping, just pick a significant negative vertical velocity, apply that to the character at the instant they jump, and decrement it by your per-frame gravity increment. That's really all you need for something like Mario, unless you're looking for a 3d background for your 2d side scroller.

    If you want to get fancier, you can try to take an object's impact force into account, making falling objects hurt people or crack pavement or something. For this, use the formula for Kinetic Energy: KE = 1/2 * M * V^2, where M is mass and V is velocity.

    0 讨论(0)
  • 2020-12-28 20:46

    The physics in most 2D side-scrolling platform games are so simple that you could easily implement them yourself. What kind of effects are you looking for?

    0 讨论(0)
  • 2020-12-28 20:48

    If you got the time you could use PhysX but its likely an over kill for 2D. Besides that if you plan on having your game work on a PC and want some cool physics, try googling for "verlet integration" I know there are quite a few verlet implementations around (nice for particles and 2D rag-dolls).

    0 讨论(0)
  • 2020-12-28 20:52

    To answer the second part of your question, if you want to get a handle on how a simple 2D platformer works, take a read through the tutorials for N. Yes, N is a flash-based game but that doesn't mean it isn't constructed like a "real" game, so the collision detection (and response) tutorials are very much applicable. They're a straightforward read with some intuitive demos embedded in the page to show off the geometric concepts.

    0 讨论(0)
  • 2020-12-28 20:53

    What platform are you looking for? What library you use will depend on this.

    For the XNA framework, Farseer is pretty nice.

    0 讨论(0)
提交回复
热议问题