Original article, reproduced please indicate the source: http://blog.csdn.net/zhy_cheng/article/details/8480048
Drawing, In the cocos2d-x comes testcpp, including drawing points, straight lines, polygon (filled and not filled), circles, besell curves.
First, override the draw method of the parent class in the helloworld class.
virtual void draw();
In the source file, delete the class capacity in init. The init method should be executed before draw, which will overwrite the effect we have drawn. After deletion, the init method is as follows:
bool HelloWorld::init(){ bool bRet = false; do { CC_BREAK_IF(! CCLayer::init()); bRet = true; } while (0); return bRet;}
Then write the following code in the draw method:
Void helloworld: Draw () {check_gl_error_debug ();/* draws a straight line. The default width is 1, the color is white, not transparent, and the glable (gl_line_smooth ); by default, the backend width is not set */gllinewidth (1.0f); ccdrawcolor4b (255,255,255,255); ccdrawline (CCP (480,320), CCP (); check_gl_error_debug (); gllinewidth (5.0f); ccdrawcolor4b (0,255, 0,320); ccdrawline (CCP (128), CCP (); check_gl_error_debug (); // ccpointsize ); this is useless. ccdrawcolor4b (0,255,255,128); ccdrawpoint (CCP (240,200); check_gl_error_debug (); // draw ccpoint points [] = {CCP (60, 60) together ), CCP (0,255,255,255), CCP (60, 70), CCP ()}; ccpointsize (4); ccdrawcolor4b (); ccdrawpoints (points, 4 ); // draw a green circle with 10 segments gllinewidth (1); ccdrawcolor4b (0,255, 0,255); ccdrawcircle (CCP (240,160), // center 100, // radius 1, // if the line from the center of the circle to the circle is set to true, // This value is the angle of the line, 0 is horizontal to left, counter-clockwise 360, // how many parts of the circle are divided into true // whether there is a line from the center of the circle to the circle); // draw a polygon ccdrawcolor4b (255,255, 0,255); gllinewidth (1 ); ccpoint vertices [] = {CCP (100,100), CCP (50, 50), CCP (50,100), CCP (), CCP ()}; ccdrawpoly (vertices, 5, true // closed); // filled polygon gllinewidth (1); ccpoint filledvertices [] = {CCP (0,120), CCP (50,120), CCP (50,170 ), CCP (25,200), CCP (0,170)}; ccdrawsolidpoly (filledvertices, 5, ccc4f (0.5f, 0.5f, 1, 1) // fill color ); // The beiser curve ccdrawcolor4b (255,255, 0,255); ccdrawcubicbeier (CCP (0, 0), // The starting point CCP (50, 50), // The Control Point CCP (250,100 ), // Control Point CCP (300,300), // target point 100 // the curve obtained by dividing into segments); // restore the default gllinewidth (1); ccdrawcolor4b (255,255,255,255 ); ccpointsize (1 );}
The annotations in the Code are clearly explained. Here is:
If the source code is used, there is no need to upload it. I have posted all the code.