Box2D Functions

Jump to navigation Jump to search

This article is an overview of Box2D related functions. For in an in depth overview of this system please see this article.

Official Box2D Logo


Before a physics body can be created it needs to be given a definitive shape of its mass. That is where shape objects come into play, they were designed to be reusable on multiple bodies and fixtures for performance. It is also imperative to note that Box2D requires that shapes be convex and not concave and that the points be in clockwise order, otherwise your game may crash as the behaviour is unexpected.

Illustrates the difference between concave and convex shapes.

After you have the points of a shape ready or have modified an existing shape you need to build the shape with the appropriate function below. You can modify, build, and rebuild as many times as you like. However they will not change any of the bodies or fixtures which were built with the shapes. Shape Constants also exist for the shape functions.


Once you have a shape you can use it to create a fixture on a physics body. Fixtures help define mass properties of a body, for instance a bike is generally made of mutliple parts, two wheels and the frame. You should note that due to limitations of the Box2D engine fixtures when deleted are not immediately removed from the body they were created from until it is also deleted.


Physics bodies make your fixtures and shapes active and will cause them to react to forces and can be attached to joints. Multiple fixtures on bodies are also supported, for instance a bike could be simulated will two wheel fixtures and a fixture for the frame connected by joints.


Joints help bind physical bodies together and can also for instance allow you to clamp the rotation of a body. Think of a swinging pendulum in a grandfather clock, the pendulum would be attached in the center to a joint.


Physics worlds contain your bodies and their fixtures, you must create one before you can create any bodies or fixtures. They also provide handy dandy helper functions for instance setting whether or not all bodies contained in the world are allowed to sleep or how many bodies exist in the world.

See Also