博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cocos2d-x3.0 经常使用绘图方法
阅读量:7075 次
发布时间:2019-06-28

本文共 3647 字,大约阅读时间需要 12 分钟。

HelloWorldScene.h

例如,下面的代码被添加:

protected:    void onDraw(const kmMat4 &transform, bool transformUpdated);    CustomCommand _customCommand;
HelloWorldScene.cpp

void HelloWorld::draw(cocos2d::Renderer *renderer, const kmMat4 &transform, bool transformUpdated){    _customCommand.init(1);    _customCommand.func = CC_CALLBACK_0(HelloWorld::onDraw, this,transform,transformUpdated);    renderer->addCommand(&_customCommand);}void HelloWorld::onDraw(const kmMat4 &transform, bool transformUpdated){    kmGLPushMatrix();    kmGLLoadMatrix(&transform);            /*直线*/    CHECK_GL_ERROR_DEBUG();    DrawPrimitives::drawLine(VisibleRect::leftBottom(), VisibleRect::rightTop());            CHECK_GL_ERROR_DEBUG();        glLineWidth( 5.0f );    DrawPrimitives::setDrawColor4B(255,0,0,255);    DrawPrimitives::drawLine( Point(0, 0), Point(100, 100) );    // draw big point in the center    DrawPrimitives::setPointSize(64);    DrawPrimitives::setDrawColor4B(100, 0, 255, 128);    DrawPrimitives::drawPoint(VisibleRect::center());     CHECK_GL_ERROR_DEBUG();            // draw 4 small points    Point points[] = { Point(60,60), Point(70,70), Point(160,70), Point(170,60) };    DrawPrimitives::setPointSize(10);    DrawPrimitives::setDrawColor4B(0,10,255,255);    DrawPrimitives::drawPoints( points, 4);        CHECK_GL_ERROR_DEBUG();        // draw a green circle with 10 segments    glLineWidth(16);    DrawPrimitives::setDrawColor4B(0, 255, 0, 255);    DrawPrimitives::drawCircle( VisibleRect::center(), 100, 0, 10, false);        CHECK_GL_ERROR_DEBUG();    // draw a green circle with 50 segments with line to center    glLineWidth(2);    DrawPrimitives::setDrawColor4B(0, 255, 255, 255);    DrawPrimitives::drawCircle( VisibleRect::center(), 150, CC_DEGREES_TO_RADIANS(90), 50, false);        CHECK_GL_ERROR_DEBUG();                    // draw a pink solid circle with 50 segments    glLineWidth(2);    DrawPrimitives::setDrawColor4B(255, 0, 255, 255);    DrawPrimitives::drawSolidCircle( VisibleRect::center() + Point(140,0), 40, CC_DEGREES_TO_RADIANS(90), 50, 1.0f, 1.0f);        CHECK_GL_ERROR_DEBUG();                    // open yellow poly    DrawPrimitives::setDrawColor4B(255, 255, 0, 255);    glLineWidth(5);    Point vertices[] = { Point(10,10), Point(50,50), Point(100,50), Point(150,100), Point(200,150) };    DrawPrimitives::drawPoly( vertices, 5, false);        CHECK_GL_ERROR_DEBUG();        // filled poly    glLineWidth(1);    Point filledVertices[] = { Point(0,120), Point(50,120), Point(50,170), Point(25,200), Point(0,170) };    DrawPrimitives::drawSolidPoly(filledVertices, 5, Color4F(0.5f, 0.5f, 1, 1 ) );        // closed purble poly    DrawPrimitives::setDrawColor4B(255, 0, 255, 255);    glLineWidth(2);    Point vertices2[] = { Point(30,130), Point(30,230), Point(50,200) };    DrawPrimitives::drawPoly( vertices2, 3, true);        CHECK_GL_ERROR_DEBUG();                            // draw quad bezier path    DrawPrimitives::drawQuadBezier(VisibleRect::leftTop(), VisibleRect::center(), VisibleRect::rightTop(), 50);        CHECK_GL_ERROR_DEBUG();            // draw cubic bezier path    DrawPrimitives::drawCubicBezier(VisibleRect::center(), Point(VisibleRect::center().x+30,VisibleRect::center().y+150), Point(VisibleRect::center().x+60,VisibleRect::center().y-300),Point(VisibleRect::center().x+90,VisibleRect::center().y+150),100);        CHECK_GL_ERROR_DEBUG();            //draw a solid polygon    Point vertices3[] = {Point(60,160), Point(70,190), Point(100,190), Point(90,160)};    DrawPrimitives::drawSolidPoly( vertices3, 4, Color4F(1,1,0,1) );        CHECK_GL_ERROR_DEBUG();        //end draw    kmGLPopMatrix();}

你可能感兴趣的文章
Android 使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突...
查看>>
windows平台下编辑的内容传到linux平台出现中文乱码的解决办法【转】
查看>>
js为元素动态添加css代码
查看>>
冒泡排序 和 归并排序
查看>>
软件包管理 之 用apt+synaptic 在线安装或升级Fedora core 4.0 软件包── 为新手指南...
查看>>
DBGRIDEH保存"显示标题"
查看>>
spring mvc3 example
查看>>
动态添加用户控件
查看>>
vimrc
查看>>
js 模块化
查看>>
C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 数据权限增强、范围权限增强...
查看>>
Linux启动过程
查看>>
122. Best Time to Buy and Sell Stock II
查看>>
V模型与测试级别
查看>>
Elasticsearch安装
查看>>
根据IP定位城市
查看>>
Excel之tab键
查看>>
MyEclipse使用总结——使用MyEclipse打包带源码的jar包
查看>>
yii2 安装
查看>>
A008-drawable资源
查看>>