HI all, is there an easy way to get an on-screen representation of the joints etc. in the chipmunk 'space'. The chipmunk demos use drawspace.c to draw outline objects and lines/spots for joints and constraints ... but it's beyond me how to integrate that into an iphone/cocos2d project. thanks
displaying chipmunk joints/shapes
(10 posts) (8 voices)-
Posted 1 year ago #
-
The cpConstraintNode and cpShapeNode in the spacemanager know how to draw the constraints and shapes they are attached to...
http://code.google.com/p/chipmunk-spacemanager/
cpConstraintNode can draw most but not all kinds of constraints
Posted 1 year ago # -
you could just throw a
ccDrawLine(body1->p, body2->p);
into your draw method.Posted 1 year ago # -
EDIT: I'm aware this is old, but I haven't seen a good fix for this, and figured I'd share if others were curious.
I was having the same issue, the way I resolved it was simple;
Copy drawSpace.h and drawSpace.c into your project,
drawSpace.c -> right-click -> "Get Info"
Under the General Tab, click the drop-down menu for "File Type",
Select "sourcecode.c.objc"Your project should now build correctly!
Now we need drawing functions, so in the .m file for your layer, add the following:
drawSpaceOptions options = { 0,//Draw Hash 0,//Draw BBoxes 1,//Draw Shapes 4.0f,//Collision Point Size 0.0f,//Body Point Size 1.5f//Line Thickness };Now, under your layer, override the draw function:
-(void) draw { drawSpace(space, &options); }And, your Chipmunk Physics scene should draw!
Posted 1 year ago # -
I included drawSpace.c in my layer, added the options for drawSpace, and overrode the draw method using the above code. I've verified that the draw method is being called...but I don't see anything relating to chipmunk. I've tried hiding my sprites, but that didn't work. Any ideas?
Posted 1 year ago # -
that seems to work quite nicely...thanks!
Posted 1 year ago # -
well...it didn't quite work as I had hoped. The coordinates were screwed up (probably my fault), and it was displaying 3 bodies per actual body.
So, to append to the user above's post about how to implement drawSpace...it does actually work! In your layer, obviously make sure you include drawSpace.c (including drawSpace.h didn't seem to help). I found it helped if you didn't copy the drawSpace code over to your project, as it's included with cocos2d already. Just include drawSpace.c, and if you have the entire cocos2d project in your project, it should know what you're talking about. Additionally, make sure every node (CCSprite or otherwise) has a negative value for the z-axis. drawSpace uses the opengl primitives drawing methods, which it seems are always a z value of 0. Having other things (like a background) at a z value of 0 seemed to hide the debug drawing. I've laid out my entire scene in terms of negative z axis values, and the drawSpace method works swimmingly now. It seems that it was always drawing, which I suspected due to the drop in fps, but it was behind everything else. NOTE; Don't make the layer.visibility = false. It need to be visible for you to see the debug drawing. I hope that helps a future googler, as the rest of this has helped me.
Posted 1 year ago # -
I know this is old, but I wanted to say thanks!
I needed to verify my chipmunk physics stuff today, make sure that my sprite code wasn't the problem. Dropped this into my project, set my sprites' visibility to NO and your debug code works great! Thanks a bunch for posting this, it's a great help in narrowing down chipmunk problems.
Posted 1 month ago #
Reply
You must log in to post.