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设成负数就可以了

  • 相关阅读:
    数据库编程总结
    Excel文件操作方式比较
    大数据导入Excel
    导出Excel
    duilib库分析: 消息流程分析
    ucosII移植
    Log Parser Studio 分析 IIS 日志
    google 搜索关键字技巧
    未知的反物质世界的瞎想
    Scratch 简单的小游戏 --- 碰碰球
  • 原文地址:https://www.cnblogs.com/skyhacker/p/3667037.html
Copyright © 2011-2022 走看看