WPF, C#, Objective C and a little Math

cocos2dx – ccDrawCircle, solid, filled?

I tried to draw a solid cicle in cocos2dx. It was quite terrible to modify ccDrawCircle for this. My app crashed with openGL errors which I was not able to handle. Few days later (after I left this idea and used spites instead) I realized that I should use ccDrawSolidPoly. What a shame :)

Here is the code anyway:

void ccDrawSolidCircle(const CCPoint& center, float radius, float angle, unsigned int segments, float scaleX, float scaleY, ccColor4F color) 
	// Copypaste from ccDrawCircle to build poli buffer.	
    const float coef = 2.0f * (float)M_PI/segments;

    CCPoint *poli = (CCPoint*)calloc(sizeof(CCPoint)*(segments+1), 1);
    if (!poli)

    for(unsigned int i = 0;i <= segments; i++) {
        float rads = i*coef;
	poli[i].x = radius * cosf(rads + angle) * scaleX + center.x;
        poli[i].y = radius * sinf(rads + angle) * scaleY + center.y;
    ccDrawSolidPoly(poli, segments + 1, color);

Meanwhile, Arcade Monsterball grew up to quite colorful game. Still a lot TODOs, but major things are done:

Categorised as: cocos2dx, iOS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>