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 #include13 #include 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);