zoukankan      html  css  js  c++  java
  • cocos2d-x中DrawNode常见的图像绘制函数

    //绘制矩形  (‘起始点’ , ‘目标点’ , ‘填充颜色’)

        auto rect=DrawNode::create();

        rect->drawRect(Vec2(0,0),Vec2(100,150), Color4F(1.0,0,0,1.0));

        this->addChild(rect);

        

        

        //绘制指定曲率的曲线  ('点数组','张力','段落','颜色')

        //参数说明:

        //congfig:点数组

        //tension:张力

        //segments:段落

        //color:颜色

        auto cardinalspline=DrawNode::create();

       

        auto array = PointArray::create(4);

        array->addControlPoint(Vec2(20, 20));

        array->addControlPoint(Vec2(40, 10));

        array->addControlPoint(Vec2(-10, 10));

        array->addControlPoint(Vec2(60, -10));

        array->addControlPoint(Vec2(10, 50));

        cardinalspline->drawCardinalSpline(array, 3, 10, Color4F(1.0,1.0,1.0,1));

        this->addChild(cardinalspline);

        

        

        //绘制默认曲率的曲线

        auto cat=DrawNode::create();

        cat->drawCatmullRom(array, 20, Color4F(1.0, 1.0, 1.0, 1.0));

        this->addChild(cat);

        

        

        //绘制圆  参数说明: (‘原点’,‘半径’,‘弧度’,‘分段(越大越接近圆)’,‘原点到弧度的线(bool)’,‘线条x缩放’,‘线条y缩放’,‘颜色’)

        auto circle=DrawNode::create();

        circle->drawCircle(Vec2(0, 0), 100, 45, 100, false, 1.0, 1.0, Color4F(1.0,1.0,1.0,1));

        this->addChild(circle);

        

        //绘制线段          (‘起点’ , ‘终点’ , ‘半线宽’ , ‘填充颜色’)

        auto segment=DrawNode::create();

        segment->drawSegment(Vec2(0, 0), Vec2(20, 20), 3.0, Color4F(0.4,0.6,0.8,1));

        this->addChild(segment);

        

        //绘制三角形         (‘顶点1′ , ‘顶点2′ , ‘顶点3′ , ‘填充颜色’)

        auto triangle=DrawNode::create();

        triangle->drawTriangle(Vec2(20,11), Vec2(133,44), Vec2(44,133), Color4F(0.5,0.6,0.7,1));

        this->addChild(triangle);

        

        //绘制多边形        (‘顶点数组’ , ‘顶点个数’ , ‘填充颜色’ , ‘轮廓粗细’ , ‘轮廓颜色’)

        auto polygon=DrawNode::create();

        Vec2 verts[]={Vec2(12,22),Vec2(56,66),Vec2(88,98),Vec2(124,54),Vec2(144,88)};//顶点数组

        polygon->drawPolygon(verts, 5, Color4F(1.0,0,0,1), 2, Color4F(0,0,1.0,1));

        this->addChild(polygon);

        

        //绘制二次贝塞尔图形        (‘起点’ , ‘控制点’ , ‘终点’ , ‘分段数’ , ‘填充颜色’)

        auto quad=DrawNode::create();

        quad->drawQuadBezier(Vec2(12,10), Vec2(22,33), Vec2(111,111), 20, Color4F(0.1,1.0,0.2,1));

        this->addChild(quad);

        

        //绘制三次贝塞尔图形    (‘起点’ , ‘控制点1′ , ‘控制点2′ , ‘终点’ , ‘分段数’ , ‘填充颜色’)

        auto cubic=DrawNode::create();

        cubic->drawCubicBezier(Vec2(0,0), Vec2(33,23), Vec2(75,96), Vec2(44,33), 22, Color4F(0.7,0,0,1));

        this->addChild(cubic);

        

        //绘制线段  ('起点','终点','宽度','颜色')

        auto dsegment=DrawNode::create();

        dsegment->drawSegment(Vec2(20, 22), Vec2(20,100), 2, Color4F(1.0,0.1,0.8,1));

        this->addChild(dsegment);

        

        //绘制线   ('起点','终点','颜色')

        auto line=DrawNode::create();

        line->drawLine(Vec2(33,33), Vec2(222,222), Color4F(1.0,1.0,0.2,1));

        this->addChild(line);

        

        //绘制圆点      (‘位置’ , ‘圆点半径’ , ‘填充颜色’)

        auto dot=DrawNode::create();

        dot->drawDot(Vec2(0,0), 5, Color4F(1.0, 1.0, 1.0, 1.0));

        rect->addChild(dot);    

        

        //设置坐标位置

        rect->setPosition(visibleSize/2);//设置矩形位置居中

        dot->setPosition(Vec2(0, 0));//设置圆点的位置

        cardinalspline->setPosition(visibleSize/2);//设置曲线位置

        circle->setPosition(visibleSize/2);

        segment->setPosition(visibleSize/2);

        triangle->setPosition(visibleSize/2);

        polygon->setPosition(visibleSize/5);

        quad->setPosition(Vec2(230,20));

        cubic->setPosition(visibleSize/2);

        dsegment->setPosition(Vec2(22,22));

        line->setPosition(Vec2(44,22));

        cat->setPosition(Vec2( visibleSize.width/2+50,visibleSize.height/2+20));

        

    drawnode.png  

  • 相关阅读:
    上周热点回顾(11.2912.5)
    上周热点回顾(11.1511.21)
    上周热点回顾(11.2211.28)
    上周热点回顾(12.1312.19)
    Bambook程序达人赛报名公告
    HTML5技术专题上线啦!
    “博客无双,以文会友”活动公告
    上周热点回顾(12.612.12)
    [转]Java RMI之HelloWorld篇
    中国现代远程与继续教育网 统考 大学英语(B)考试大纲
  • 原文地址:https://www.cnblogs.com/liugangBlog/p/6285937.html
Copyright © 2011-2022 走看看