Cocos2d-x之绘不规则多边形

自定义的方法

Poly.h

 

 1 //
 2 //  Poly.h
 3 //  L01DrawingAPI
 4 //
 5 //  Created by Mac OS 10.9.3 on 15-3-30.
 6 //
 7 //
 8 
 9 #ifndef __L01DrawingAPI__Poly__
10 #define __L01DrawingAPI__Poly__
11 
12 #include <iostream>
13 #include <cocos2d.h>
14 
15 using namespace cocos2d;
16 
17 namespace bobo{
18     class Poly:public Node {
19         
20     private:
21         Point ps[3];//定义一个三个点的点数组
22         
23     public:
24         
25         virtual bool init();
26         virtual void draw();
27         CREATE_FUNC(Poly);
28     };
29 }
30 
31 #endif /* defined(__L01DrawingAPI__Poly__) */

 

 

 

Poly.cpp

 

 1 //
 2 //  Poly.cpp
 3 //  L01DrawingAPI
 4 //
 5 //  Created by Mac OS 10.9.3 on 15-3-30.
 6 //
 7 //
 8 
 9 #include "Poly.h"
10 
11 namespace bobo {
12     
13     bool Poly::init(){
14         //定义各个定点
15         ps[0] = Point(0, 0);
16         ps[1] = Point(100, 0);
17         ps[2] = Point(200, 100);
18         
19         
20         return true;
21     }
22     
23     void Poly::draw(){
24         
25         //绘制一个不规则的多边形(定点,定点的个数,多边形是否是闭合的)
26         //DrawPrimitives::drawPoly(const cocos2d::Point *vertices,
27         //                         unsigned int numOfVertices, bool closePolygon);
28         DrawPrimitives::drawPoly(ps, 3, true);
29         
30     }
31 }

 

 

 

 

bool HelloWorld::init()

auto p = bobo::Poly::create();

    p->setPosition(Point(100, 300));

    addChild(p);

转载于:https://www.cnblogs.com/dudu580231/p/4377083.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值