![]() |
Box2D Render Library
Game Physics with a 2D Physics Engine
|
This library lets you draw Box2D bodies using circles and lines so you can check that they line up correctly with your sprites.
The remainder of this page is divided into five sections. Section 2 lists the controls and their corresponding actions, Section 3 tells you how to build it, Section 4 gives you a list of actions to take in the game to see some of its important features, Section 5 gives a breakdown of the code, and Section 6 addresses the question "what next?".
This project compiles into a library, so there are no keyboard controls here.
This code uses SAGE and Box2D. Make sure that you have followed the SAGE Installation Instructions and the Box2D Installation Instructions. Navigate to the folder 6. Box2D Render Library in your copy of the sage-physics repository. Run checkenv.bat to verify that you have set the environment variables correctly. Open Box2D Renderer.sln with Visual Studio and build the Release configuration. Alternatively, run Build.bat to build both Release and Debug configurations.
There's no executable file to run here, remember, it just compiles into a library file. If you're interested, the library files are x64\Release\Box2D Renderer.lib and x64\Debug\Box2D Renderer.lib.
This library consists of a simple class CBox2DRenderer that will help you draw Box2D bodies using circles and lines in SAGE. To use it you only need to either instantiate or derive your renderer class from CBox2DRenderer and then call CBox2DRenderer::Drawb2Body with a pointer to an instance of b2Body to draw its b2Shapes using lines and circles. Read the rest of code to learn how to access the parts that make up a b2Body.
Next, take a look at the Box2D Bouncy Things Toy.