Cocos2d-x之绘制点

Cocos2d-x之绘制点

自定义的方法

Point.h

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

 

 

Point.cpp

 1 //
 2 //  Points.cpp
 3 //  L01DrawingAPI
 4 //
 5 //  Created by Mac OS 10.9.3 on 15-3-30.
 6 //
 7 //
 8 
 9 #include "Points.h"
10 
11 namespace bobo {
12     
13     bool Points::init(){
14         
15         return true;
16     }
17     
18     void Points::draw(){
19         
20         //绘制一个颜色随机的50*50的点
21         for (int y = 0; y < 50; y ++) {
22             for (int x = 0; x < 50; x ++) {
23                 DrawPrimitives::setDrawColor4B(rand() % 256, rand() % 256, rand() % 256, 255);
24                 DrawPrimitives::drawPoint(Point(x, y));
25             }
26         }
27         
28     }
29 }

 

 

bool HelloWorld::init()

  auto points = bobo::Points::create();

    points->setPosition(Point(500, 300));

    addChild(points);

posted @ 2015-03-30 23:46  silent-bobo  阅读(358)  评论(0编辑  收藏  举报