Cocos2d circular genie (the circle sprite)

Source: Internet
Author: User

There is a simple special effect in the project, and a circle needs to be drawn. This circle has the layer and scaling attributes, and was originally intended to be drawn directly using ccdrawcircle, however, using this function is not convenient for circular scaling,

There is no layer attribute.

So I thought of putting this ccdrawcircle into the genie to draw it. That's all the attributes!

However, the process of rewriting the ccsprite init and draw functions is not so smooth. I will not elaborate on it here.Code.

Class primarysprite: Public ccsprite {protected: cccolor4f color; public: Virtual void draw () ;}; class circlesprite: Public primarysprite {PRIVATE: ccpoint center; // float radius of the center of the circle; // float width of the radius; // bool fill of the line width; // whether the line is filled. Public: // The static circlesprite * Create (ccpoint CEN, int rad, float width, cccolor4f color) {circlesprite * psprite = new circlesprite (); If (psprite & psprite-> Init ()) // Psprite-> initwithtexture (null, ccrectmake (CEN. x, CEN. x, rad * 2, rad * 2) {// psprite-> width = width; psprite-> center = CEN; psprite-> radius = rad; psprite-> color = color; psprite-> setposition (CEN); // note that the sprite location must be set here // psprite-> autorelease (); Return psprite ;} cc_safe_delete (psprite); return NULL;} public: void draw () {gllinewidth (width); ccdrawcolor4f (color. r, color. g, color. b, color. a); // according to the half of the circle Diameter to calculate the number of split parts. Generally, ccdrawcircle (ccpointzero, radius, 0, radius * 2.0, false) is enough. // note that coordinates () are used here )! }};

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.