From 8063b9b9fb1ed50d30bb7ccbd914a7ff25e96e7d Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 26 Nov 2012 17:23:36 +0800 Subject: [PATCH] give a guide information to run Box2dTest --- .../TestCpp/Classes/Box2DTest/Box2dTest.cpp | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/samples/TestCpp/Classes/Box2DTest/Box2dTest.cpp b/samples/TestCpp/Classes/Box2DTest/Box2dTest.cpp index a4501487a1..acae98aebf 100644 --- a/samples/TestCpp/Classes/Box2DTest/Box2dTest.cpp +++ b/samples/TestCpp/Classes/Box2DTest/Box2dTest.cpp @@ -11,7 +11,9 @@ enum { Box2DTestLayer::Box2DTestLayer() : m_pSpriteTexture(NULL) +, world(NULL) { +#if CC_ENABLE_BOX2D_INTEGRATION setTouchEnabled( true ); setAccelerometerEnabled( true ); @@ -41,12 +43,20 @@ Box2DTestLayer::Box2DTestLayer() label->setPosition(ccp( VisibleRect::center().x, VisibleRect::top().y-50)); scheduleUpdate(); +#else + CCLabelTTF *pLabel = CCLabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION\n to run this test case", + "Arial", + 18); + CCSize size = CCDirector::sharedDirector()->getWinSize(); + pLabel->setPosition(ccp(size.width/2, size.height/2)); + + addChild(pLabel); +#endif } Box2DTestLayer::~Box2DTestLayer() { - delete world; - world = NULL; + CC_SAFE_DELETE(world); //delete m_debugDraw; } @@ -133,6 +143,7 @@ void Box2DTestLayer::draw() // CCLayer::draw(); +#if CC_ENABLE_BOX2D_INTEGRATION ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position ); kmGLPushMatrix(); @@ -140,6 +151,7 @@ void Box2DTestLayer::draw() world->DrawDebugData(); kmGLPopMatrix(); +#endif } void Box2DTestLayer::addNewSpriteAtPosition(CCPoint p) @@ -165,17 +177,17 @@ void Box2DTestLayer::addNewSpriteAtPosition(CCPoint p) fixtureDef.friction = 0.3f; body->CreateFixture(&fixtureDef); - CCNode *parent = this->getChildByTag(kTagParentNode); - - //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is - //just randomly picking one of the images - int idx = (CCRANDOM_0_1() > .5 ? 0:1); - int idy = (CCRANDOM_0_1() > .5 ? 0:1); -#if CC_ENABLE_BOX2D_INTEGRATION - CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture,CCRectMake(32 * idx,32 * idy,32,32)); - parent->addChild(sprite); - sprite->setBody(body); - sprite->setPTMRatio(PTM_RATIO); + CCNode *parent = this->getChildByTag(kTagParentNode); + + //We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is + //just randomly picking one of the images + int idx = (CCRANDOM_0_1() > .5 ? 0:1); + int idy = (CCRANDOM_0_1() > .5 ? 0:1); +#if CC_ENABLE_BOX2D_INTEGRATION + CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture,CCRectMake(32 * idx,32 * idy,32,32)); + parent->addChild(sprite); + sprite->setBody(body); + sprite->setPTMRatio(PTM_RATIO); sprite->setPosition( ccp( p.x, p.y) ); #endif }