关闭

Cocos2d-x中的draw绘制

标签: Cocos2d-xdraw绘制
2820人阅读 评论(0) 收藏 举报
分类:
【一】:函数


       //1.设置绘制颜色

1.ccDrawColor4B("红","绿","蓝","透明");

       //2.设置绘制线宽

2.glLineWidth(线条宽度);

       //3.绘制一条直线

3.ccDrawLine("起点坐标","终点坐标");

       //4.设置点的大小

4.ccPointSize("半径");

       //5.绘制一个点

5.[1]ccDrawPoint("点的坐标");

5.[2]ccDrawPoints("点的坐标数组","数量");

       //6.绘制一个圆形

6.[1]ccDrawCircle("中心点坐标","半径f","角度f","分段数","显示半径","X轴放大倍数f","Y轴放大倍数f");

6.[2]ccDrawCircle("中心点坐标","半径f","角度f","分段数","显示半径");

       //7.绘制空心多边形

7.ccDrawPoly("顶点数组","点数量","是否自动封闭");

       //8.绘制实心多边形

8.ccDrawSolidPoly("顶点数组","点数量","颜色4F");

       //9.绘制填充矩形

9.ccDrawSolidRect("对角顶点1","对角顶点2","颜色4F");

       //10.绘制空心矩形

10.ccDrawRect("对角顶点1","对角顶点2");

       //11.绘制平面贝赛尔曲线

11.ccDrawQuadBezier("起始点","控制点","结束点","分段数");

       //12.绘制立体贝赛尔曲线

12.ccDrawCubicBezier("起始点","控制点1","控制点2","结束点","分段数");


颜色:

ccDrawColor4B("红f","绿f","蓝f","透明f");//红、绿、蓝、透明、满值均为255

ccDrawColor4F("红f","绿f","蓝f","透明f");//红、绿、蓝、满值均为255,透明满值为1


【二】:示例


1.老规矩,先开始新建个项目命名Drawdemo

2.疯狂编码:


Drawdemo.h


1.重写draw函数

virtual void draw();


[gl.paea.cn-draw1.png]


Drawdemo.cpp

       这里注意,一定要保留背景,否则透明度没法体现,即使设置为0也不透明。


实现draw函数


void Drawdemo::draw(){

   //-new-//

   CCSize mysize=CCDirector::sharedDirector()->getWinSize();

   //画个猥琐的直线

   ccDrawColor4B(255,255,255,130);

   glLineWidth(3);

   ccDrawLine(ccp(100,200),ccp(mysize.width-100,200));

   //再画个可爱的圈圈

   ccDrawColor4B(255,255,100,190);

   glLineWidth(3);

   ccDrawCircle(ccp(mysize.width/2,mysize.height/2),100,0,360,1,2,1);

   //再来画个点

   ccDrawColor4B(255,25,200,250);

   glLineWidth(3);

   ccPointSize(10);

   ccDrawPoint(ccp(mysize.width/2,mysize.height/2));

   //再来画个空心矩形

   ccDrawColor4B(24,25,200,140);

   glLineWidth(3);

   ccDrawRect(ccp(100,100),ccp(300,200));

   //再来个实心的

   ccDrawSolidRect(ccp(110,210),ccp(310,110),ccc4f(255,255,255,0.5f));

   //再来画个空心多边形

   ccDrawColor4B(240,225,100,130);

   glLineWidth(3);

   CCPoint Polyarray[]={ccp(20,100),ccp(50,40),ccp(250,420),ccp(510,450),ccp(210,140)};

   ccDrawPoly(Polyarray,5,1);

   //再来个实心的多边形

   CCPoint Polyarray2[]={ccp(120,150),ccp(150,420),ccp(350,120),ccp(310,250),ccp(320,170)};

   ccDrawSolidPoly(Polyarray2,5,ccc4f(142,245,70,0.3f));

   //绘制平面贝赛尔曲线

   ccDrawColor4B(100,100,100,255);

   ccDrawQuadBezier(ccp(0,320),ccp(160,100),ccp(480,320),100);

   //绘制立体贝赛尔曲线

   ccDrawColor4B(200,200,200,255);

   ccDrawCubicBezier(ccp(0,0),ccp(160,300),ccp(320,20),ccp(480,320),100);

   //-new-//

}
【转载】
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:64357次
    • 积分:1120
    • 等级:
    • 排名:千里之外
    • 原创:46篇
    • 转载:19篇
    • 译文:0篇
    • 评论:7条
    最新评论