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 )! }};