cocos2dx之box2d画刚体外边框
来源:互联网 发布:海贼王好看的小说知乎 编辑:程序博客网 时间:2024/05/09 04:26
其实这些代码都可以在示例项目中找到,我以3.0引擎为例把代码贴出来:
首先到工程到引擎目录下tests/cpp-tests/Classes/Box2DTestBed中将GLES-Render.cpp和GLES-Render.h拷贝到工程中
其次在.h中添加#include "GLES-Render.h"并加入以下代码
<span style="font-family: Arial, Helvetica, sans-serif;"> virtual void draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated) override;</span>
kmMat4 _modelViewMV; void onDraw(); CustomCommand _customCommand;
<pre name="code" class="cpp"> GLESDebugDraw* m__debugDraw;然后在.cpp中
void MyGameLayer::draw(Renderer *renderer, const kmMat4 &transform, bool transformUpdated){ Layer::draw(renderer, transform, transformUpdated);//我的<span style="font-family: Arial, Helvetica, sans-serif;">MyGameLayer类继承自Layer</span> GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); kmGLPushMatrix(); kmGLGetMatrix(KM_GL_MODELVIEW, &_modelViewMV); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(MyGameLayer::onDraw, this); renderer->addCommand(&_customCommand); kmGLPopMatrix();}void MyGameLayer::onDraw(){ kmMat4 oldMV; kmGLGetMatrix(KM_GL_MODELVIEW, &oldMV); kmGLLoadMatrix(&_modelViewMV); m__world->DrawDebugData();//m__world是b2world对象 kmGLLoadMatrix(&oldMV);}
最后,在创建b2world对象的时候加入这段代码
m__debugDraw = new GLESDebugDraw(32.0); m__world->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->SetFlags(flags);
现在运行一下,就可以画出来了
不要忘了在onExit()中将这些new出来的对象删除
0 0
- cocos2dx之box2d画刚体外边框
- cocos2dx之Box2D
- cocos2dx之Box2D
- Cocos2dx之Box2D物理引擎
- cocos2dx之box2d的使用
- 【COCOS2DX-BOX2D游戏开发之二】 Box2d教程链接
- 【COCOS2DX-BOX2D游戏开发之四】 Box2D匀速运动
- cocos2dx box2d
- cocos2dx自学之使用box2d物理世界
- Cocos2dx之Box2D——刚体
- cocos2dx之box2d创建椭圆刚体
- cocos2dx 边框
- 【COCOS2DX-BOX2D游戏开发之五】 ApplyForce、ApplyImpulse、SetLinearVelocity
- Cocos2dx之Box2D详解 设置物体回复力
- Cocos2dx 3.1.1 之 在VS2012上配置Box2d
- COCOS2DX学习之box2d物理引擎在VS2012中的配置
- COCOS2DX学习之Box2D物理引擎-------物体和相互作用
- COCOS2DX学习之Box2D物理引擎-物体和相互作用
- 【LeetCode】39. Combination Sum & 40. Combination Sum II分析及解法&DFS
- inception安装步骤
- hdu5432Rikka with Array (数位dp+十进制转化为二进制)
- Windows 实现桌面截屏并保存为.jpg
- Python笔记——类定义
- cocos2dx之box2d画刚体外边框
- Swift编程基础(四):控制流
- Kinect开发环境配置:Kinect for Windows SDK + OpenCV2.4.10 + VS2010 + Win7(x64)
- Java —— JAVA读取Oracle中的blob图片字段并显示
- java多线程-需要知道的几个概念(待续..)
- 博客说明
- arm指令编译参数详解
- Ubuntu 14.04 下搭建SVN服务器 svn://
- iOS开发学习之 - 高度自适应之计算文字高度