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();
}

cocos2d-x3.0 经常使用绘图方法的更多相关文章

  1. html --- canvas --- javascript --- 绘图方法

    Canvas元素是HTML5的一部分,允许脚本语言动态渲染位图像. 如有疑问请访问链接:http://javascript.ruanyifeng.com/htmlapi/canvas.html < ...

  2. Canvas绘图方法和图像处理方法(转)

    转自:http://javascript.ruanyifeng.com/htmlapi/canvas.html 概述 Canvas API(画布)用于在网页实时生成图像,并且可以操作图像内容,基本上它 ...

  3. 如何在Cocos2D 1.0 中掩饰一个精灵(六)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 掩饰一个精灵:实现代码 打开HelloWorldLayer.m并 ...

  4. 如何在Cocos2D 1.0 中掩饰一个精灵(一)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 原帖来自Ray Wunderlich写的精彩的文章 How To ...

  5. Cocos2D v2.0至v3.x简洁转换指南(三)

    Cocos2D 3.3中的注意事项 如果你在使用Cocos2D 3.3+(是SpriteBuilder 1.3+的一部分)你将不得不替分别的换所有存在的UITouch和UITouchEvent为CCT ...

  6. Cocos2D v2.0至v3.x简洁转换指南(二)

    触摸处理 我们在稍后将完成Cocos2d 3.0中触摸处理的完整教程.而现在最重要的是知道如何去启用触摸处理在你的CCNode中: self.userInteractionEnabled = TRUE ...

  7. Java知多少(98)Graphics类的绘图方法

    Graphics类提供基本绘图方法,Graphics2D类提供更强大的绘图能力.本节讲解Graphics类,下节讲解Graphics2D. Graphics类提供基本的几何图形绘制方法,主要有:画线段 ...

  8. Java知多少(99)Graphics2D类的绘图方法

    Java语言在Graphics类提供绘制各种基本的几何图形的基础上,扩展Graphics类提供一个Graphics2D类,它拥用更强大的二维图形处理能力,提供.坐标转换.颜色管理以及文字布局等更精确的 ...

  9. 十一. 图形、图像与多媒体5.Graphics2D类的绘图方法

    Java语言在Graphics类提供绘制各种基本的几何图形的基础上,扩展Graphics类提供一个Graphics2D类,它拥用更强大的二维图形处理能力,提供.坐标转换.颜色管理以及文字布局等更精确的 ...

随机推荐

  1. java验证手机号码是否合法

    公司开发新功能须要验证手机号码,遂自己写了个出来,暂仅仅支持中国大陆手机号验证.如有不妥之处,还望大家指教,感激不尽! /** * 验证是否是正确合法的手机号码 * * @param telephon ...

  2. Android开源项目分享

    Android PDF 阅读器 http://sourceforge.net/projects/andpdf/files/ 个人记账工具 OnMyMeans http://sourceforge.ne ...

  3. NSIS:使用WinVer.nsh头文件判断操作系统版本

    原文 NSIS:使用WinVer.nsh头文件判断操作系统版本 AtLeastWin<version> 检测是否高于指定版本 IsWin<version> 检测指定版本(唯一限 ...

  4. 百度地图 Android SDK - 个性化地图

    什么是百度个性化地图Android SDK? 百度个性化地图Android SDK是一套基于Android 2.2及以上版本号设备的应用程序接口,您能够通过该套接口实现主要的地图功能,而且能够定制地图 ...

  5. Android的相关的源代码的方法

    这里给大家介绍一个非常方便的相关法源代码. 1.打开Android SDK Manager.把你所使用的版本号的API给下载下来,例如以下图所看到的... 2.关联源代码时,将源代码关联到相应API的 ...

  6. Rust这个新的语言

    Rust这个新的语言 Rust初步(七):格式化 摘要: 在Rust中,如果要进行屏幕输出,或者写入到文件中,需要对数据进行格式化.这一篇总结一下它所支持的几种格式化方式. 这篇文章参考了以下官方文档 ...

  7. 脚本+批处理打造IIS监控器

    原文 脚本+批处理打造IIS监控器 首先说下我什么要写它,第一.它可以帮你做一件事,那就是随时给你监控你公司的网站服务器的状态,一旦你的网站出现问题不能访问了,它就会自动帮你重启IIS然后让死掉的网站 ...

  8. 编程算法 - 数丑陋 代码(C)

    数丑陋 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 我们把仅仅包括因子2, 3 和 5的数称作丑数. 求按从小到大的顺序的第5个丑数. 能够 ...

  9. [wxWidgets]_[0基础]_[经常更新进度条程序]

    场景: 1. 非常根据程序的进展需要处理业务,以更新进度条,进度条的目的是为了让用户知道业务流程的进度.一个进度条程序更友好,让用户知道在程序执行.不是没有反应. 2. 现在更新见过这两种方法的进展. ...

  10. Andriod Studio科普文章——3.大约gradle常见问题插头

    1.andriod gradle插件版本号过低. 错误位置: dependencies{ classpath 'com.android.tools.build:gradle:0.10.2' } 提示信 ...