zoukankan      html  css  js  c++  java
  • cocos2d-x box2d使用调试绘图

    cocos2d-x box2d使用调试绘图

    复制TestCpp的GLES-Render.h和GLES-Render.cpp过来。

    添加一个成员变量:

    GLESDebugDraw *m_debugDraw;
    

    初始化物理引擎的时候:

    void HNGameLayer::initPhysics()
    {
        m_debugDraw = new GLESDebugDraw(RATIO);
        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->SetFlags(flags);
        m_b2World = new b2World(b2Vec2(0, -10));
        m_b2World->SetAllowSleeping(true);          // 允许物体进入休眠状态
        m_b2World->SetContinuousPhysics(true);      // 使用连续物理碰撞检测
        m_b2World->SetDebugDraw(m_debugDraw);
        
        ....其他代码
    }
    

    重写draw函数

    void HNGameLayer::draw()
    {
        CCLayer::draw();
        if (!m_bDebug) {
            return;
        }
        ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
        
        kmGLPushMatrix();
        
        m_b2World->DrawDebugData();
        
        kmGLPopMatrix();
        
        CHECK_GL_ERROR_DEBUG();
    }
    

    防止被背景阻挡了。因为draw函数话出来的东西的z-order应该是0,把背景的z-order设成负数就可以了

  • 相关阅读:
    fs.readdirSync
    symbol
    vuex-count
    webpack2.0
    关于vuex报错
    store
    .NET MVC 验证码
    SQLServer 加密
    IE10、IE11下SCRIPT5009: “__doPostBack”未定义
    Sql Server 增加字段、修改字段、修改类型、修改默认值
  • 原文地址:https://www.cnblogs.com/skyhacker/p/3667037.html
Copyright © 2011-2022 走看看