Chapter 12. Gravity

Topics in This Chapter

12.1 Equip the Runner for Falling

12.2 Incorporate Gravity

12.3 Collision Detection, Redux

12.4 Conclusion

12.5 Exercises

In Chapter 9 you saw how to simulate gravity during a sprite’s jumps and bounces by using easing functions that slow time on the sprite’s ascent and accelerate it on the descent. That manipulation of time affects all time’s derivatives, including motion, so sprites slow as they ascend and speed up as they descend, similar to how gravity acts on the objects the sprites represent.

Sometimes, however, an approximation of gravity is not enough; for example, an artillery game should be more precise about how gravity affects rounds as they fly through the air. In this short chapter, ...

Get Core HTML5 2D Game Programming now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.