Debug draw in Cocos2d 1.0.0-rc

Official forum for the Chipmunk2D Physics Library.
Post Reply
SpudGT
Posts: 5
Joined: Wed Mar 30, 2011 8:45 pm
Contact:

Debug draw in Cocos2d 1.0.0-rc

Post by SpudGT »

Asked this over in the Cocos2d forum, but thought the Chipmunk users here may have encountered the same issue. I have been unsuccessfully trying to get Chipmunk debug drawing to work in iOS with:
- cocos2d 1.0.0-rc
- Xcode 4.0.1

I was using the following debug draw technique; adding a drawSpaceOptions structure and over-riding the draw method of my layer to include a call to drawSpace.

The trouble started when I added drawSpace.c and drawSpace.h from the external/Chipmunk/Demo directory to my project: Xcode simply hangs when trying to compile drawSpace.c.

Just for giggles I tried building and running the ChipmunkDemo using the included cocos2d-ios.xcodeproj project ... works perfectly.

My project was created using the cocos2d 1.0.0-rc Xcode 4 cocos2d/chipmunk template, and there are plenty of differences when compared to the cocos2d-ios.xcodeproj project.

Anyone have any tips to get this working?

Thanks.
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by slembcke »

You could try this:
http://files.slembcke.net/temp/ChipmunkDebugNode.tgz

It's made for Objective-Chipmunk specifically, but changing it to work with regular Chipmunk would be trivial.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
SpudGT
Posts: 5
Joined: Wed Mar 30, 2011 8:45 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by SpudGT »

Many thanks for the code. Only a few simple tweaks were needed to get the code building with regular Chipmunk, then I adjusted my z ordering and the debug drawing showed up nicely!

Now at this point ChipmunkDebugNode was converted to C, so I renamed ChipmunkDebugNode.m to ChipmunkDebugNode.c. The dreaded Xcode compile hang came back. Rename it back to ChipmunkDebugNode.m and every thing was happy again.

So I went back to drawSpace.c and renamed it to drawSpace.m ... it built and ran perfectly.

Any ideas what gives?
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by slembcke »

It was converted to C? How did you use it as a Cocos2D node then? Did you just strip out everything except for the drawing function?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
SpudGT
Posts: 5
Joined: Wed Mar 30, 2011 8:45 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by SpudGT »

Yup, just stripped everything out but the draw method. The header file ended up looking like:

#include "cocos2d.h"
#include "chipmunk.h"

void cpDebugNodeDraw(cpSpace *space);

Then I simply called cpDebugNodeDraw from my layers draw routine.
AkumaStreak
Posts: 12
Joined: Fri Apr 24, 2009 2:51 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by AkumaStreak »

Hi guys. Question on this.

First -- is that zip still your latest version of those files Scott?

Second -- I think I am having the z-order issue you had SpudGT, because I don't see any of the shapes being drawn even though draw is being called every frame. How did you determine that z-ordering was the problem/how did you fix it?

Thanks!
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by slembcke »

I think there were a couple small fixes that it needed in order to work with Chipmunk 6. Grab them out of this project instead:
http://chipmunk-physics.net/tutorials/M ... ipmunk.tgz

There are also some other bits of example code here:
http://chipmunk-physics.net/downloads.php
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
AkumaStreak
Posts: 12
Joined: Fri Apr 24, 2009 2:51 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by AkumaStreak »

I've gotten latest as suggested, integrated it, and am still having the same problem. Will try to track down SpudGT to find out what z-order tweak he made to get this working. Happy to be using latest regardless. :)
AkumaStreak
Posts: 12
Joined: Fri Apr 24, 2009 2:51 pm
Contact:

Re: Debug draw in Cocos2d 1.0.0-rc

Post by AkumaStreak »

Because I add the ChipmunkDebugNode to my layer last, z-order was fine. The issue was that my physics shapes were being drawn offscreen because of an anchor point issue (defined in Physics Editor).

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests