Page 1 of 1

Debug draw in Cocos2d 1.0.0-rc

Posted: Mon Apr 04, 2011 8:03 am
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.

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Mon Apr 04, 2011 9:43 am
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.

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Mon Apr 04, 2011 9:14 pm
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?

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Tue Apr 05, 2011 8:44 am
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?

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Tue Apr 05, 2011 6:20 pm
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.

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Tue Jul 26, 2011 7:22 pm
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!

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Wed Jul 27, 2011 9:24 am
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

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Fri Jul 29, 2011 4:39 pm
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. :)

Re: Debug draw in Cocos2d 1.0.0-rc

Posted: Fri Jul 29, 2011 9:47 pm
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.