Box2D Forums

It is currently Wed Apr 16, 2014 6:03 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Jul 02, 2011 5:19 am 
Offline

Joined: Sat Jul 02, 2011 5:04 am
Posts: 11
Hello! I'm a beginner in Box2D and I wanna draw Box2D bodies (or whole world) using PyGame. I've watched in the pygame_main.py 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?


Top
 Profile  
 
PostPosted: Fri Jul 08, 2011 7:13 pm 
Offline

Joined: Mon Feb 18, 2008 12:30 am
Posts: 88
If you are using the SVN (pybox2d >= 2.1), you can look at http://code.google.com/p/pybox2d/source/browse/trunk/examples/simple_01.py 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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group