Cocos2d-x常用功能-绘图API:绘制点、线条、圆形、矩形、多边形

第三阶段:常用功能4

primitive  /'prɪmɪtɪv/
  1. adj. 原始的, 早期的
  2. 简单的; 粗糙的
  3. n. 文艺复兴前的画家或雕刻家; 早期的艺术家
destination  /,destɪ'neɪʃ(ə)n/ n.  目的地, 终点

1.Cocos2d-x绘图API使用说明
class Shape: public Node {
public :
//重写 draw方法             用DrawPrimitives
    virtual void draw(){
       
    };
   
   
virtual bool init(){
       
return true ;
    }
   
    CREATE_FUNC(Shape);
};

2.Cocos2d-x绘制矩形
    void Rect::draw(){
        DrawPrimitives::setDrawColor4B(
255 , 0 , 0 , 255 );
        DrawPrimitives::drawRect(Point(
0 , 0 ), Point( 100 , 100 ));
    }

3.Cocos2d-x绘制填充矩形
    void SRect::draw(){
        DrawPrimitives::drawSolidRect(Point(
0 , 0 ), Point( 100 , 100 ), Color4F( 0 , 0 , 1 , 1 ));
    }
4.Cocos2d-x绘制圆形
圆心,半径,角度,分隔的线段,是否绘制一个连到中心的线
    void Circle::draw(){
        DrawPrimitives::drawCircle(Point(
0 , 0 ), 50 , M_PI* 2 , 50 , true );
    }
5.Cocos2d-x绘制填充圆形
    void SCircle::draw(){
        DrawPrimitives::setDrawColor4B(
0 , 255 , 0 , 255 );
        DrawPrimitives::drawSolidCircle(Point(
0 , 0 ), 50 , M_PI* 2 , 50 );
    }
6.Cocos2d-x绘制多边形
顶点  顶点得数目 是否关闭几何图形
#ifndef __L01DrawingAPI__Poly__
#define __L01DrawingAPI__Poly__

#include <iostream>
#include
<cocos2d.h>

using namespace cocos2d;

namespace jikexueyuan {
   
   
class Poly: public Node{
       
   
private :
        Point ps[
3 ];
       
   
public :
       
virtual bool init();
       
       
virtual void draw();
       
       
        CREATE_FUNC(Poly);
       
    };
   
}

#endif /* defined(__L01DrawingAPI__Poly__) */



#include "Poly.h"
namespace jikexueyuan {
   
   
bool Poly::init(){
       
        ps[
0 ] = Point( 0 , 0 );
        ps[
1 ] = Point( 100 , 0 );
        ps[
2 ] = Point( 100 , 100 );
       
       
return true ;
    }
   
   
   
void Poly::draw(){
        DrawPrimitives::drawPoly(ps,
3 , true );
    }
   
}

7.Cocos2d-x绘制填充多边形
顶点、 顶点得数目、填充的颜色
#ifndef __L01DrawingAPI__SPoly__
#define __L01DrawingAPI__SPoly__

#include <iostream>
#include
<cocos2d.h>

using namespace cocos2d;

namespace jikexueyuan {
   
   
   
class SPoly: public Node{
       
   
private :
        Point points[
5 ];
       
   
public :
       
virtual bool init();
       
virtual void draw();
       
        CREATE_FUNC(SPoly);
    };
   
}

#endif /* defined(__L01DrawingAPI__SPoly__) */



#include "SPoly.h"

namespace jikexueyuan {
   
   
bool SPoly::init(){
       
        points[
0 ] = Point( 0 , 0 );
        points[
1 ] = Point( 100 , 0 );
        points[
2 ] = Point( 100 , 100 );
        points[
3 ] = Point( 50 , 50 );
        points[
4 ] = Point( 0 , 100 );
       
       
return true ;
    }
   
   
void SPoly::draw(){
       
        DrawPrimitives::drawSolidPoly(points,
5 , Color4F( 1 , 1 , 0 , 1 ));
    }
   
}
8.Cocos2d-x绘制线条
起始点、目标点
    void Line::draw(){
        DrawPrimitives::drawLine(Point(
0 , 0 ), Point( 100 , 100 ));
    }
9.Cocos2d-x绘制点
    void Points::draw(){
       
       
for ( int y = 0 ; y< 50 ; y++) {
           
for ( int x= 0 ; x< 50 ; x++) {
                DrawPrimitives::setDrawColor4B(rand()%
256 , rand()% 256 , rand()% 256 , 255 );
                DrawPrimitives::drawPoint(Point(x, y));
            }
        }
       
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值