Box2D
Encyclopedia
Box2D is a free
open source
2-dimensional
physics simulator
engine
written in C++
by Erin Catto and published under the zlib license
. It has been used in Crayon Physics Deluxe
, Rolando
, Fantastic Contraption
, Incredibots
, Angry Birds
, Tiny Wings
, Transformice
, Stripe physics2, and many online Flash games, as well as iPhone, iPad and Android games using the Corona Framework.
2006. On September 11, 2007 it was released as open source on Sourceforge
. On January 17, 2010 Box 2D moved the project to Google Code
for hosting
On March 6, 2008, version 2.0 was launched, introducing continuous collision detection and revamping the API.
, and is usable on any system with a C++ compiler available. The engine may be compiled in fixed point
and floating point
modes, and has been used on the Nintendo DS
, Wii
, and several mobile phones (including Android and iPhone
) as well as most major operating systems.
The engine has been ported to many other programming languages and environments, including Java
, Adobe Flash
(in ActionScript
and haXe
languages), C#, JavaScript
, and D
. Bindings
exist to use the compiled library from Python
and DarkBasic
.
On October 30, 2009, it was announced that Box2D was being integrated into the Torque 2D game engine.
simulation. It can simulate bodies composed of convex polygon
s, circle
s, and edge shapes. Bodies are joined together with joints and acted upon by force
s. The engine also applies gravity, friction
, and restitution
.
Box2D's collision detection and resolution system consists of three pieces: an incremental sweep and prune
broadphase, a continuous collision detection unit, and a stable linear-time contact solver. These algorithms allow efficient simulations of fast bodies and large stacks without missing collisions or causing instabilities.
presentations that Erin Catto has given. Box2D Lite uses many of the same algorithms as Box2D, but has a smaller feature set.
The Chipmunk physics engine
(written in C) and Phys2D (written in Java) are both partially based on Box2D Lite.
iPhone
engine,. An article in the Adobe Edge newsletter discusses the use of Box2D in Flash games.
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...
open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
2-dimensional
Dimension
In physics and mathematics, the dimension of a space or object is informally defined as the minimum number of coordinates needed to specify any point within it. Thus a line has a dimension of one because only one coordinate is needed to specify a point on it...
physics simulator
Physics engine
A physics engine is computer software that provides an approximate simulation of certain physical systems, such as rigid body dynamics , soft body dynamics, and fluid dynamics, of use in the domains of computer graphics, video games and film. Their main uses are in video games , in which case the...
engine
Game engine
A game engine is a system designed for the creation and development of video games. There are many game engines that are designed to work on video game consoles and personal computers...
written in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
by Erin Catto and published under the zlib license
Zlib License
The zlib License is a permissive free software license which defines the terms under which the zlib and libpng software libraries can be distributed. It is also used by other free software packages....
. It has been used in Crayon Physics Deluxe
Crayon Physics
Crayon Physics Deluxe is a puzzle game designed by Petri Purho and released on January 7, 2009. An early version, titled Crayon Physics, won the grand prize at the Independent Games Festival in 2008. It features a heavy emphasis on two-dimensional physics simulations, including gravity, mass,...
, Rolando
Rolando (video game)
Rolando is a puzzle-adventure video game developed by HandCircus and published by ngmoco. It was released for the iOS on December 18, 2008, and uses the Box2D game engine....
, Fantastic Contraption
Fantastic Contraption
Fantastic Contraption is a Flash-based physics game created by Colin Northway, released September 16, 2008. Northway sold the rights to the game to inXile Entertainment who released the game for iOS on January 26, 2009. A sequel, Fantastic Contraptions 2, was released July 27, 2010...
, Incredibots
Incredibots
IncrediBots is a physics simulation game produced by Grubby Games and was later purchased by Big Fish Games. It uses the Box2D Physics Engine, which allows objects created in a simple click and drag fashion to interact realistically. Users can create basic geometric shapes such as triangles,...
, Angry Birds
Angry Birds
Angry Birds is a puzzle video game developed by Finnish computer game developer Rovio Mobile. Inspired primarily by a sketch of stylized wingless birds, the game was first released for Apple's iOS in December 2009...
, Tiny Wings
Tiny Wings
Tiny Wings is an iOS game developed by German game developer Andreas Illiger, released on February 18, 2011.-Gameplay:In Tiny Wings, the player takes control of a bird whose wings are too small to fly. The goal of the game is to use hills in order to gain speed and flutter as long as possible. This...
, Transformice
Transformice
Transformice is an independent multiplayer free-to-play online platform browser game created by French designers known by their aliases Melibellule and Tigrounette. Melibellule produces the game's artwork and graphics, while Tigrounette programs the game's functions and mechanics...
, Stripe physics2, and many online Flash games, as well as iPhone, iPad and Android games using the Corona Framework.
History
Box2D was first released as "Box2D Lite", a demonstration engine to accompany a physics presentation given by Erin Catto at GDCGame Developers Conference
The Game Developers Conference is the largest annual gathering of professional video game developers, focusing on learning, inspiration, and networking...
2006. On September 11, 2007 it was released as open source on Sourceforge
SourceForge
SourceForge Enterprise Edition is a collaborative revision control and software development management system. It provides a front-end to a range of software development lifecycle services and integrates with a number of free software / open source software applications .While originally itself...
. On January 17, 2010 Box 2D moved the project to Google Code
Google Code
Google Code is Google's site for developer tools, APIs and technical resources. The site contains documentation on using Google developer tools and APIs—including discussion groups and blogs for developers using Google's developer products....
for hosting
On March 6, 2008, version 2.0 was launched, introducing continuous collision detection and revamping the API.
Cross-platform availability
Box2D is itself written in platform-independent C++C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, and is usable on any system with a C++ compiler available. The engine may be compiled in fixed point
Fixed-point arithmetic
In computing, a fixed-point number representation is a real data type for a number that has a fixed number of digits after the radix point...
and floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...
modes, and has been used on the Nintendo DS
Nintendo DS
The is a portable game console produced by Nintendo, first released on November 21, 2004. A distinctive feature of the system is the presence of two separate LCD screens, the lower of which is a touchscreen, encompassed within a clamshell design, similar to the Game Boy Advance SP...
, Wii
Wii
The Wii is a home video game console released by Nintendo on November 19, 2006. As a seventh-generation console, the Wii primarily competes with Microsoft's Xbox 360 and Sony's PlayStation 3. Nintendo states that its console targets a broader demographic than that of the two others...
, and several mobile phones (including Android and iPhone
IPhone
The iPhone is a line of Internet and multimedia-enabled smartphones marketed by Apple Inc. The first iPhone was unveiled by Steve Jobs, then CEO of Apple, on January 9, 2007, and released on June 29, 2007...
) as well as most major operating systems.
The engine has been ported to many other programming languages and environments, including Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...
(in ActionScript
ActionScript
ActionScript is an object-oriented language originally developed by Macromedia Inc. . It is a dialect of ECMAScript , and is used primarily for the development of websites and software targeting the Adobe Flash Player platform, used on Web pages in the form of...
and haXe
HaXe
haXe is a versatile open-source high-level multiplatform programming language described on its website as a "universal language".It can produce:* Flash applications and games* Multi-platform client-side web applications* Apache CGI web applications...
languages), C#, JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
, and D
D (programming language)
The D programming language is an object-oriented, imperative, multi-paradigm, system programming language created by Walter Bright of Digital Mars. It originated as a re-engineering of C++, but even though it is mainly influenced by that language, it is not a variant of C++...
. Bindings
Language binding
In computing, a binding from a programming language to a library or OS service is an API providing that service in the language.Many software libraries are written in systems programming languages such as C or C++...
exist to use the compiled library from Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
and DarkBasic
DarkBASIC
DarkBASIC is a commercial game creation programming language released by The Game Creators. The language is a structured form of BASIC and is similar to AMOS on the Amiga. The purpose of the language is game creation using Microsoft's DirectX from a BASIC programming language. It is faster and...
.
On October 30, 2009, it was announced that Box2D was being integrated into the Torque 2D game engine.
Features
Box2D performs constrained rigid bodyRigid body
In physics, a rigid body is an idealization of a solid body of finite size in which deformation is neglected. In other words, the distance between any two given points of a rigid body remains constant in time regardless of external forces exerted on it...
simulation. It can simulate bodies composed of convex polygon
Convex polygon
In geometry, a polygon can be either convex or concave .- Convex polygons :A convex polygon is a simple polygon whose interior is a convex set...
s, circle
Circle
A circle is a simple shape of Euclidean geometry consisting of those points in a plane that are a given distance from a given point, the centre. The distance between any of the points and the centre is called the radius....
s, and edge shapes. Bodies are joined together with joints and acted upon by force
Force
In physics, a force is any influence that causes an object to undergo a change in speed, a change in direction, or a change in shape. In other words, a force is that which can cause an object with mass to change its velocity , i.e., to accelerate, or which can cause a flexible object to deform...
s. The engine also applies gravity, friction
Friction
Friction is the force resisting the relative motion of solid surfaces, fluid layers, and/or material elements sliding against each other. There are several types of friction:...
, and restitution
Coefficient of restitution
The coefficient of restitution of two colliding objects is a fractional value representing the ratio of speeds after and before an impact, taken along the line of the impact...
.
Box2D's collision detection and resolution system consists of three pieces: an incremental sweep and prune
Sweep and prune
In physical simulations, sweep and prune is a broad phase algorithm used during collision detection to limit the number of pairs of solids that need to be checked for collision, i.e. intersection. This is achieved by sorting the starts and ends of the bounding volume of each solid along a number...
broadphase, a continuous collision detection unit, and a stable linear-time contact solver. These algorithms allow efficient simulations of fast bodies and large stacks without missing collisions or causing instabilities.
Related engines
An earlier version of the Box2D engine, now known as Box2D Lite, was released primarily for educational purposes, based on a series of yearly Game Developers ConferenceGame Developers Conference
The Game Developers Conference is the largest annual gathering of professional video game developers, focusing on learning, inspiration, and networking...
presentations that Erin Catto has given. Box2D Lite uses many of the same algorithms as Box2D, but has a smaller feature set.
The Chipmunk physics engine
Chipmunk physics engine
The Chipmunk SDK is a portable open-source 2D physics engine written in C99 by Scott Lembcke and published under the MIT license. Middleware physics engines like Chipmunk allow game developers to avoid writing their own code to handle the complex physics interactions possible in modern games...
(written in C) and Phys2D (written in Java) are both partially based on Box2D Lite.
Articles
Itterheim and Wenderlich describe the usage of Box2D in the Cocos2dCocos2d
Cocos2d is an open source 2D game framework. There are two versions, one written in Python and one written in Objective-C targeting iOS.-iOS port:...
iPhone
IPhone
The iPhone is a line of Internet and multimedia-enabled smartphones marketed by Apple Inc. The first iPhone was unveiled by Steve Jobs, then CEO of Apple, on January 9, 2007, and released on June 29, 2007...
engine,. An article in the Adobe Edge newsletter discusses the use of Box2D in Flash games.