How to draw Box2D using PyGame?

Discuss issues specific the Python port of Box2D
Peter Robur
Posts: 12
Joined: Sat Jul 02, 2011 5:04 am

How to draw Box2D using PyGame?

Postby Peter Robur » Sat Jul 02, 2011 5:19 am

Hello! I'm a beginner in Box2D and I wanna draw Box2D bodies (or whole world) using PyGame. I've watched in the in Python Box2D TestBed but I didn't very understand it. Probably because I don't know Box2D very good yet. Can anyone give me a simple tutorial on how to draw Box2D bodies, shapes or world using PyGame?

Posts: 88
Joined: Mon Feb 18, 2008 12:30 am

Re: How to draw Box2D using PyGame?

Postby kne » Fri Jul 08, 2011 7:13 pm

If you are using the SVN (pybox2d >= 2.1), you can look at for a simple drawing example. If you are using a previous version (i.e., 2.0.x), you will just have to read and understand the manual (debug drawing) or one of the back-ends.

The short of it is that you loop over the bodies, then loop over each fixture (shape) in that body, apply the body's transform to the specific shape's vertices (in the case of a polygon) or center (in the case of a circle), adjust for MKS units -> pixels (this is explained in the manual countless times), and then draw to the screen with whatever library you are using.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest