Original article:
These two days to play cocos2d-x and box2d, found that cocos2d-x version 2.0 to use the old method debug rendering will be wrong, so found a new method to debug draw:
First, add the following in your header file:
Public:
//.....
Virtual void draw ();
//.....
Then implement it in your cpp:
Void HelloWorld: draw () {CCLayerColor: draw (); ccglablevertexattribs (attri); kmGLPushMatrix (); glScalef (CC_CONTENT_SCALE_FACTOR (), CC_CONTENT_SCALE_FACTOR (), 1.0f ); world-> DrawDebugData (); kmGLPopMatrix ();}
Note the following two points: the first is CCLayerColor: draw ();
If you inherit CCLayerColor, use CCLayerColor: draw (); otherwise, use CCLayer: draw ();
If you use CCLayer: draw () When inheriting CCLayerColor, the color of your layers will be lost.
Second, there is a retina mode on IOS. If it is not enabled, it doesn't matter but it is enabled, so the debug draw renders only half the size.
To solve this problem, add one sentence
GlScalef (CC_CONTENT_SCALE_FACTOR (), CC_CONTENT_SCALE_FACTOR (), 1.0f );