Note that there are some explanatory texts on larger screens.

plurals
  1. POb2body is not showing in b2world- Box2D
    primarykey
    data
    text
    <pre><code>b2BodyDef myBodyDef; myBodyDef.type = b2_dynamicBody; myBodyDef.position.Set(_screenSize.width / 3, _screenSize.height / 3); myBodyDef.angle = 0; b2Body* dynamicBody = m_world-&gt;CreateBody(&amp;myBodyDef); b2PolygonShape boxShape; boxShape.SetAsBox(10, 10); PTM_RATIO = 40.0f; m_debugDraw = new GLESDebugDraw(PTM_RATIO); m_world-&gt;SetDebugDraw(m_debugDraw); b2FixtureDef boxFixtureDef; boxFixtureDef.shape = &amp;boxShape; boxFixtureDef.density = 1; dynamicBody-&gt;CreateFixture(&amp;boxFixtureDef); </code></pre> <p>I am using box2d in cocos2d-x 2.2.1</p> <p>and using this simple code to show a b2body in the screen but for using the </p> <pre><code>m_debugDraw = new GLESDebugDraw(PTM_RATIO); </code></pre> <p>I am getting </p> <pre><code>Classes/HelloWorldScene.cpp:164: error: undefined reference to 'GLESDebugDraw::GLESDebugDraw(float)' </code></pre> <p>i am doing with their reference project only but i couldnt find why the object is not showing in the screen. </p> <p>And if i am not declaring the value for the PTM_RATIO , it is giving error as </p> <pre><code>PTM_RATIO value was not declared in this scope. </code></pre> <h2>UPDATE : 1:</h2> <p>By including the GLES_Render.cpp in my android.mk file the error related to the PTM_RATIO Is cleared.</p> <h2>UPDATE : 2:</h2> <p>this is my draw method code</p> <pre><code>void HelloWorld::draw() { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // CCLayer::draw(); ccGLEnableVertexAttribs (kCCVertexAttribFlag_Position); kmGLPushMatrix(); m_world-&gt;DrawDebugData(); kmGLPopMatrix(); } </code></pre> <h2>UPDATE : 3:</h2> <p>My final code:</p> <p>My android.mk file</p> <pre><code>LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := game_shared LOCAL_MODULE_FILENAME := libgame LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/GLES_Render.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ /home/user/adt/cocos2dx/external/Box2D \ /home/user/adt/cocos2dx/external LOCAL_WHOLE_STATIC_LIBRARIES := cocos_testcpp_common LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) $(call import-module,CocosDenshion/android) $(call import-module,extensions) $(call import-module,external/Box2D) $(call import-module,external/chipmunk) </code></pre> <p>and this is how i defined the b2world</p> <pre><code>m_world = new b2World(gravity); m_world-&gt;SetAllowSleeping(true); m_world-&gt;SetContinuousPhysics(true); m_debugDraw = new GLESDebugDraw(PTM_RATIO); m_world-&gt;SetDebugDraw(m_debugDraw); uint32 flags = 0; flags += b2Draw::e_shapeBit; // flags += b2Draw::e_jointBit; /*flags += b2Draw::e_aabbBit; flags += b2Draw::e_pairBit; flags += b2Draw::e_centerOfMassBit;*/ m_debugDraw-&gt;SetFlags(flags); </code></pre> <p>then in a menu sprite click callback method i am using this to show a b2body</p> <pre><code>b2BodyDef myBodyDef; myBodyDef.type = b2_dynamicBody; //this will be a dynamic body myBodyDef.position.Set(_screenSize.width / 3, _screenSize.height / 3); //set the starting position myBodyDef.angle = 0; //set the starting angle b2Body* dynamicBody = m_world-&gt;CreateBody(&amp;myBodyDef); dynamicBody-&gt;SetType(b2_staticBody); b2PolygonShape boxShape; boxShape.SetAsBox(200, 200); b2FixtureDef boxFixtureDef; boxFixtureDef.shape = &amp;boxShape; boxFixtureDef.density = 1; dynamicBody-&gt;CreateFixture(&amp;boxFixtureDef); </code></pre> <p>Please suggest me where i am doing wrong . i couldn't find it. thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload