Phaser Box2D
A high-performance, industry-standard 2D physics engine built on Box2D v3, delivering incredibly realistic and engaging web game experiences.
High Performance
Our comprehensive conversion of Box2D v3 has been optimized for browser performance, featuring a soft step rigid body solver that delivers excellent stability in physics calculations. This ensures realistic collisions and interactions for immersive gaming experiences.
The island-based sleep management enhances performance by pausing calculations for inactive objects, allowing complex, high-speed games to maintain stable physics without compromising speed. Your games will achieve smooth performance even in demanding scenarios.
Accuracy
The Continuous Collision Detection (CCD) system handles high-velocity scenarios with precision, from fast projectiles to rapid character movements. Ray casts and queries provide detailed insights into your physics world, ensuring accurate tracking of all interactions.
The refined physics engine ensures object interactions behave naturally and predictably, reducing bugs and inconsistencies. This lets developers create reliable gameplay experiences while maintaining accurate simulation.
Fast Integration
Quickly integrate Phaser Box2D with the framework of your choice and focus on creating your game. Built using modern JavaScript standards, this hand-tuned engine mirrors the original C version while maintaining a lean 70KB size - perfect for instant messenger games and playable ads.
We preserved the original C API function names, making transition easy for Box2D veterans and allowing you to leverage existing resources, whether through AI assistance or community solutions.
50+ Examples
Explore and experiment with over 50 examples demonstrating the core elements of Box2D.
From complete mini-games to feature showcases, each with the full JavaScript source and an example runner. Here are just a few:
Continuous Collision Detection (CCD)
CCD handles high-velocity objects, ensuring they don't bypass collisions. It constantly checks for intersections, capturing every interaction between fast-moving entities. This feature is essential for high-speed gameplay, where objects like bullets, cars, or falling debris demand accurate collision responses.
Contact Events and Sensors
Contact Events provide detailed feedback on collision points, overlap durations, and distance queries, enabling responsive gameplay elements. Sensors let you create triggers or detection zones without physical interference, perfect for implementing zones or areas that respond to player presence without blocking movement.
Physics Engines Comparison
Feature | Arcade | Matter.js | Phaser Box2D |
---|---|---|---|
Stacking Stability | None | Low | Very High |
Continuous Collision Detection (CCD) | No | No | Yes |
Shape Support | Limited | High | Diverse Range + Compound Shapes |
Contact Events and Sensors | None | Available | Detailed feedback and sensors |
Joint Types | None | Distance | Revolute, Distance, Prismatic, Weld and Wheel |
Joint Interaction | None | Friction | Limits, Motors, Springs, Friction |
Industry Standard | 😅 | Personal project | Yes. 18 years of development. |
Download
You need a free Phaser account to download the examples.
Don't have one? Register now.
Files
The library is available under the MIT license.
View the GitHub repository for the Getting Started Guide.
Explore and experiment with over 50 examples demonstrating the core elements of Phaser Box2D.
From complete mini-games to feature showcases, each with the full JavaScript source and an example runner.
FAQs
Does it only work with Phaser, or can I use Pixi?
Despite its title, Phaser Box2D is compatible with any web-based tech stack or framework, including Pixi, React, Vue and more. It is provided as an ESM compatible Module and is not deeply integrated with Phaser itself.
Of course, being Phaser Studio, we include lots of helpful functions that ease use of Box2D with Phaser itself. And these are included with the download. However, using Phaser isn't a requirement.
Is Phaser Box2D Open Source?
Yes. The original C version of Box2D itself is released under an MIT license and we firmly respect that. Our conversion of it includes thousands of lines of custom code. Which is also now released under the MIT license.
How complicated is it to use?
Complexity is, of course, subjective. However we feel it would be remiss to say that this is perfect for complete beginners. You are expected to have a solid grasp of JavaScript and ideally previous experience with physics systems.
We provide tutorials, API Documentation and over 50 examples to learn from. Plus, you can ask us questions in our Discord. Even so, Box2D does have a certain level of complexity and if you are unsure if it's right for you we would recommend you read some of our public tutorials first to get an understanding of how it works.
What support is available for Phaser Box2D?
Free community-based support is available via our forum and Discord.
Customers who have Pro or Enterprise level Phaser Studio accounts can receive priority support from the Phaser Studio team. Contact your team representative for more details.
Diverse Shape Support
Supports an array of shapes — convex polygons, circles, capsules, chains, and rounded polygons — allowing complex object modeling. This versatility means you can create intricate environments and interactive items, from basic walls to irregular terrain or composite enemies.
Multiple Shapes per Body
Allows combining various shapes in one body, providing flexibility in designing composite structures with multi-part interactions. Ideal for complex characters or objects requiring unique collision behaviors for different body parts, such as vehicles or ragdolls.
Collision Filtering
Offers precise control over which objects can interact. This feature is invaluable for games needing unique layers of collision, like separating player collisions from environmental or enemy hits.
Ray Casts, Shape Casts, and Overlap Queries
Delivers powerful tools to detect line-of-sight, aiming, and field-of-view interactions. By casting rays or shapes, you can create sophisticated interactions, such as AI behaviors, aiming mechanics, or accurate projectile targeting.
Physics Simulation: Stability and Realism
Robust Soft Step Rigid Body Solver
Box2D Version 3.0 introduces a new Soft Step solver, delivering greater stability across the board compared to previous versions. It effectively manages higher mass ratios, longer body chains, larger stacks, and more. Built on soft constraints and sub-stepping, this solver ensures accurate, stable simulations, even when stacking large numbers of bodies.
Continuous Physics for Fast Translations and Rotations
Box2D employs specialized algorithms to prevent tunneling and missed interactions with high-speed objects or rapidly rotating entities. Its collision algorithms can interpolate the motion of two bodies to pinpoint the first time of impact (TOI), ensuring no collision is overlooked. Speculative collision is used for realistic results in fast-paced gameplay.
Island-Based Sleep Management
Boosts performance by pausing calculations for objects at rest, freeing up processing power for active elements. This method is particularly helpful for games with dense environments, as it automatically allocates resources where they're needed most.
Versatile Joint Types
Box2D v3.0 offers an extensive range of joints — including revolute, distance, prismatic, weld, and wheel joints — that allow you to create complex structures and mechanisms. Whether it's a swinging door, rotating wheels, or extending pistons, these joints empower the creation of realistic, interactive machines.
Joint Limits, Motors, Springs, and Friction
Allows for detailed control over joint movement and interaction, from limiting motion ranges to applying motor-driven forces. You can easily simulate mechanisms like spring-loaded objects, friction-controlled surfaces, or tension-based interactions.
Joint and Contact Forces
Provides precise data on the forces exerted during interactions, helping simulate responsive reactions and dynamic gameplay elements. With access to these forces, you can create scenes where player actions yield tactile, physical feedback—ideal for everything from destructible environments to realistic combat dynamics.
Body Movement Events and Sleep Notification
Sends alerts when an object's state changes, enabling highly responsive and event-driven gameplay. Sleep notifications keep inactive objects from taxing the system, while movement events allow for real-time reactions to changes, making simulations efficient and highly interactive.