【问题标题】:Fill a circle with color in cocos2d在 cocos2d 中用颜色填充一个圆圈
【发布时间】:2013-02-17 11:13:34
【问题描述】:

我用 cocos2d 画这样的圆圈

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

这是我增加中心以便它可以移动的球的状态。 这会产生红色边框圆圈,但我想用颜色和 alpha 填充圆圈。

我也尝试子类化 CCSprite 类并调用

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

在 init 方法中,但同样只有圆圈的边框有颜色。

所以我的问题是如何用颜色填充一个圆圈,我错过了什么?

【问题讨论】:

标签: ios objective-c iphone cocos2d-iphone


【解决方案1】:

设置不透明度试试这个

来自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);        
}
}

【讨论】:

    【解决方案2】:

    谢谢你们!我没想过要更改 cocos2d 代码来完成我的工作,我不知道这是否正确,但它对我有用!

    正如雷切尔·加伦所说。我去了CCDrawingPrimatives.m并改变了

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

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

    它成功了。

    【讨论】:

    • @RachelGallen 我可以添加透明度吗?
    • 你的意思是你想降低不透明度或者你想混合两个圆圈?我只是在吃午饭,一分钟后就会吃饱
    • 我想要降低透明度。我对混合很好奇
    • 要降低不透明度,您必须先启用混合模式。我会试着给你找一些示例代码
    • 另一个有用的链接仅供参考是cocos2d-iphone.org/forum/topic/13597感谢投票!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多