Common Drawing Method of cocos2d-x3.0

Source: Internet
Author: User


HelloWorldScene. h

Add the following code:

protected:    void onDraw(const kmMat4 &transform, bool transformUpdated);    CustomCommand _customCommand;

HelloWorldScene. cpp

Void HelloWorld: draw (cocos2d: Renderer * renderer, const kmMat4 & transform, bool transformUpdated) {_ customCommand. init (1); _ customCommand. func = CC_CALLBACK_0 (HelloWorld: onDraw, this, transform, transformUpdated); renderer-> addCommand (& _ customCommand);} void HelloWorld: onDraw (const kmMat4 & transform, bool transformUpdated) {kmGLPushMatrix (); kmGLLoadMatrix (& transform);/* straight line */trim (); DrawPrimitives: drawLine (VisibleRect: leftBottom (), VisibleRect :: rightTop (); CHECK_GL_ERROR_DEBUG (); glLineWidth (5.0f); DrawPrimitives: setDrawColor4B (255,0, 0,255); DrawPrimitives: drawLine (Point (0, 0 ), point (100,100); // draw big point in the center DrawPrimitives: setPointSize (64); DrawPrimitives: setDrawColor4B (100, 0,255,128); DrawPrimitives: drawPoint (VisibleRect :: center (); CHECK_GL_ERROR_DEBUG (); // draw 4 small points Point points [] = {Point (60,60), Point (70,70), Point (160,70 ), point (17255,255)}; DrawPrimitives: setPointSize (10); DrawPrimitives: setDrawColor4B (,); DrawPrimitives: drawPoints (points, 4); vertex (); // draw a green circle with 10 segments glLineWidth (16); DrawPrimitives: setDrawColor4B (0,255, 0,255); DrawPrimitives: drawCircle (VisibleRect: center (), 100, 0, 10, false); CHECK_GL_ERROR_DEBUG (); // draw a green circle with 50 segments with line to center glLineWidth (2); DrawPrimitives: setDrawColor4B (0,255,255,255); DrawPrimitives :: drawCircle (VisibleRect: center (), 150, CC_DEGREES_TO_RADIANS (90), 50, false); CHECK_GL_ERROR_DEBUG (); // draw a pink solid circle with 50 segments glLineWidth (2 ); drawPrimitives: setDrawColor4B (255, 0,255,255); DrawPrimitives: drawSolidCircle (VisibleRect: center () + Point (), 40, weight (90), 50, 1.0f, 1.0f); CHECK_GL_ERROR_DEBUG (); // open yellow poly DrawPrimitives: setDrawColor4B (255,255, 0,255); glLineWidth (5); Point vertices [] = {Point ), point (50, 50), Point (150,100), Point (200,150), Point ()}; DrawPrimitives: drawPoly (vertices, 5, false); CHECK_GL_ERROR_DEBUG (); // filled poly glLineWidth (1); Point filledVertices [] = {Point (0,120), Point (50,120), Point (50,170), Point (25,200 ), point (0,170)}; DrawPrimitives: drawSolidPoly (filledVertices, 5, Color4F (0.5f, 0.5f, 1, 1); // closed purble poly DrawPrimitives: setDrawColor4B (255, 0,255,255); glLineWidth (2); Point vertices2 [] = {Point (30,130), Point (30,230), Point (50,200)}; DrawPrimitives: drawPoly (vertices2, 3, true); random (); // draw quad bezr path DrawPrimitives: drawquadbezr (VisibleRect: leftTop (), VisibleRect: center (), VisibleRect: rightTop (), 50); CHECK_GL_ERROR_DEBUG (); // draw cubic bezr path DrawPrimitives: drawcubicbezr (VisibleRect: center (), Point (VisibleRect: center (). x + 30, VisibleRect: center (). y + 150), Point (VisibleRect: center (). x + 60, VisibleRect: center (). y-300), Point (VisibleRect: center (). x + 90, VisibleRect: center (). y + 150), 100); CHECK_GL_ERROR_DEBUG (); // draw a solid polygon Point vertices3 [] = {Point (60,160), Point (70,190), Point (100,190 ), point (90,160)}; DrawPrimitives: drawSolidPoly (vertices3, 4, Color4F (,); CHECK_GL_ERROR_DEBUG (); // end draw kmGLPopMatrix ();}















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.