zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    1scala基础
    3scala高级
    03spark kafka
    01spark基础
    04spark streaming
    2scala集合
    02spark sql
    学习java程序设计环境的心得
    第五章继承
    第二周学习Java心得
  • 原文地址:https://www.cnblogs.com/dudu580231/p/4377083.html
Copyright © 2011-2022 走看看