cundeng 发表于 2016-1-3 01:57:01

Cocos2d-x之绘制填充不规则多边形

  Cocos2d-x之绘制填充不规则多边形
  自定义的方法
  SPoly.h



1 //
2 //SPoly.h
3 //L01DrawingAPI
4 //
5 //Created by Mac OS 10.9.3 on 15-3-30.
6 //
7 //
8
9 #ifndef __L01DrawingAPI__SPoly__
10 #define __L01DrawingAPI__SPoly__
11
12 #include <iostream>
13 #include <cocos2d.h>
14
15 using namespace cocos2d;
16
17 namespace bobo {
18   
19   class SPoly:public Node{
20         
21   private:
22         
23         Point points;
24         
25   public:
26         
27         virtual bool init();
28         virtual void draw();
29         CREATE_FUNC(SPoly);
30         
31   };
32   
33   
34 }
35
36 #endif /* defined(__L01DrawingAPI__SPoly__) */
  
  
  SPoly.cpp



1 //
2 //SPoly.cpp
3 //L01DrawingAPI
4 //
5 //Created by Mac OS 10.9.3 on 15-3-30.
6 //
7 //
8
9 #include "SPoly.h"
10
11 namespace bobo{
12
13   bool SPoly::init(){
14
15         points = Point(0,0);
16         points = Point(100,0);
17         points = Point(100,100);
18         points = Point(50,50);
19         points = Point(0,100);
20         
21         return true;
22   }
23   
24   void SPoly::draw(){
25         
26         //绘制黄色的填充不规则多边形
27         DrawPrimitives::drawSolidPoly(points, 5, Color4F(1, 1, 0, 1));
28         
29   }
30   
31 }
  
  
  bool HelloWorld::init()中
  auto sp = bobo::SPoly::create();
  sp->setPosition(Point(300, 300));
  addChild(sp);
页: [1]
查看完整版本: Cocos2d-x之绘制填充不规则多边形