【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第十六课:Cocos2D-X几何图形1-3

前端之家收集整理的这篇文章主要介绍了【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第十六课:Cocos2D-X几何图形1-3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

【麦可网】Cocos2d-X跨平台游戏开发---学习笔记

第十六课:Cocos2D-X几何图形1-3

=======================================================================================================================================================================

课程目标:

-Cocos2D-X几何图形绘制

课程重点:

-Cocos2D-X几何图形绘制

-Cocos2D-X节点理解

考核目标:

-Cocos2D-X几何图形绘制

-Cocos2D-X节点理解

=======================================================================================================================================================================

一、几何图形绘制

参考代码:tests->DrawPrimitives Test
void DrawPrimitivesTest::draw()
{
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw a simple line
	// The default state is:
	// Line Width: 1
	// color: 255,255,255 (white,non-transparent)
	// Anti-Aliased
//	glEnable(GL_LINE_SMOOTH);
//直线绘制
    ccDrawLine( VisibleRect::leftBottom(),VisibleRect::rightTop() );
    
	CHECK_GL_ERROR_DEBUG();
    
	// line: color,width,aliased
	// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
	// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
//	glDisable(GL_LINE_SMOOTH);
	glLineWidth( 5.0f );	//设置线的宽度,opengl的设置将会影响后面的画线
//设置颜色
	ccDrawColor4B(255,255);
    ccDrawLine( VisibleRect::leftTop(),VisibleRect::rightBottom() );
    
	CHECK_GL_ERROR_DEBUG();
    
	// TIP:
	// If you are going to use always the same color or width,you don't
	// need to call it before every draw
	//
	// Remember: OpenGL is a state-machine.
    
	// draw big point in the center
//改变点的尺寸和颜色
	ccPointSize(64);
	ccDrawColor4B(0,128);
    ccDrawPoint( VisibleRect::center() );
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw 4 small points
//绘制四个点
	CCPoint points[] = { ccp(60,60),ccp(70,70),ccp(60,60) };
	ccPointSize(4);
	ccDrawColor4B(0,255);
	ccDrawPoints( points,4);
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw a green circle with 10 segments
//绘制10段的圆
	glLineWidth(16);
	ccDrawColor4B(0,255);
//参数依次是:1.中心点 2.半径 3.角度 4.几段 5.是否画一条半径
    ccDrawCircle( VisibleRect::center(),100,10,false);
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw a green circle with 50 segments with line to center
	glLineWidth(2);
	ccDrawColor4B(0,255);
    ccDrawCircle( VisibleRect::center(),50,CC_DEGREES_TO_RADIANS(90),true);
    
	CHECK_GL_ERROR_DEBUG();
    
	// open yellow poly
//绘制指定5个点的多边形
	ccDrawColor4B(255,255);
	glLineWidth(10);
	CCPoint vertices[] = { ccp(0,0),ccp(50,50),ccp(100,100),100) };
	ccDrawPoly( vertices,5,false);
    
	CHECK_GL_ERROR_DEBUG();
	
	// filled poly
//绘制填充颜色的多边形
	glLineWidth(1);
	CCPoint filledVertices[] = { ccp(0,120),170),ccp(25,200),ccp(0,170) };
	ccDrawSolidPoly(filledVertices,ccc4f(0.5f,0.5f,1,1 ) );
    
    
	// closed purble poly
//绘制紫色的闭合图形
	ccDrawColor4B(255,255);
	glLineWidth(2);
	CCPoint vertices2[] = { ccp(30,130),ccp(30,230),200) };
	ccDrawPoly( vertices2,3,true);
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw quad bezier path
//绘制四次贝塞尔曲线
    ccDrawQuadBezier(VisibleRect::leftTop(),VisibleRect::center(),VisibleRect::rightTop(),50);
    
	CHECK_GL_ERROR_DEBUG();
    
	// draw cubic bezier path
//绘制三次贝塞尔曲线 
    ccDrawCubicBezier(VisibleRect::center(),ccp(VisibleRect::center().x+30,VisibleRect::center().y+50),ccp(VisibleRect::center().x+60,VisibleRect::center().y-50),VisibleRect::right(),100);
    
	CHECK_GL_ERROR_DEBUG();
    
    //draw a solid polygon
	CCPoint vertices3[] = {ccp(60,160),190),ccp(90,160)};
//ccc4f,参数既可以是0-1,也可以是0-255
    ccDrawSolidPoly( vertices3,4,ccc4f(1,1) );		
    
	// restore original values
//恢复原始值
	glLineWidth(1);
	ccDrawColor4B(255,255);
	ccPointSize(1);
    
	CHECK_GL_ERROR_DEBUG();
}


二、贝塞尔曲线





===================================================================

总结:

绘制几何图形,让我联想到电影海洋之歌里面的各种图片的几何美。绘制幽美的轨迹就靠几何图像了。

开心一刻:

鱼说:“我时时刻刻把眼睁开是为了在你身边不舍离开。”水说:“我终日流淌不知疲倦是为了围绕你,好好把你抱紧。”锅说:“都他妈快熟了还这么多废话。”

【麦可网】Cocos2d-X跨平台游戏开发---教程下载:http://pan.baidu.com/s/1kTio1Av

【麦可网】Cocos2d-X跨平台游戏开发---笔记系列:http://blog.csdn.net/qiulanzhu

猜你在找的Cocos2d-x相关文章