Notes on how to make BOX2D debug draw in cocos2d-x 2.0

Source: Internet
Author: User

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 );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.