2

I use cocos2d and i draw circles like this

- (void)draw:(Ball*)ball {
    glLineWidth(1);
    ccDrawColor4F(255 / 255.0f, 0 / 255.0f, 0 / 255.0f, 200 / 255.0f);
    ccDrawCircle(ball._center, ball._radius, CC_DEGREES_TO_RADIANS(ball._angle), ball._segments, NO);
    ball._center = CGPointMake(ball._center.x + ball._directionX, ball._center.y + ball._directionY);
}

this is a state of the ball where i increase the center so it can move. This produce red border circles but i want to fill the circles with come color and alpha.

I also tried to subclass the CCSprite class and call

self.color = ccc3(200 / 255.0f, 0 / 255.0f, 0 / 255.0f);

in the init method but again only the border of the circle gets color.

So my question is how to fill a circle with color, what am i missing?

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
ddarellis
  • 3,912
  • 3
  • 25
  • 53

2 Answers2

2

Thank you guys! i did not thought to change cocos2d code to do my job, i dont know if this is the right way but it worked for me!

As Rachel Gallen reffered. I went to CCDrawingPrimatives.m and changed

glDrawArrays(GL_LINE_STRIP 0, (GLsizei) segs+additionalSegment);

to

glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei) segs+additionalSegment);

and it worked.

ddarellis
  • 3,912
  • 3
  • 25
  • 53
2

to set opacity try this

from http://www.cocos2d-x.org/boards/6/topics/5868

void CMySprite::draw()
{
// is_shadow is true if this sprite is to be considered like a shadow sprite, false otherwise.@
if (is_shadow)
{
ccBlendFunc    blend;
// Change the default blending factors to this one.
blend.src = GL_SRC_ALPHA;
blend.dst = GL_ONE;
setBlendFunc( blend );
// Change the blending equation to thi in order to subtract from the values already written in the frame buffer
// the ones of the sprite.
glBlendEquationOES(GL_FUNC_REVERSE_SUBTRACT_OES);
}

CCSprite::draw();

if (is_shadow)
{
 // The default blending function of cocos2d-x is GL_FUNC_ADD.
glBlendEquationOES(GL_FUNC_ADD_OES);        
}
}
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81