OGeek|极客世界-中国程序员成长平台

标题: ios - 在 cocos2d 中用颜色填充一个圆圈 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 01:09
标题: ios - 在 cocos2d 中用颜色填充一个圆圈

我用 cocos2d 画这样的圆圈

- (void)drawBall*)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 方法中,但同样只有圆圈的边框有颜色。

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



Best Answer-推荐答案


设置不透明度试试这个

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

关于ios - 在 cocos2d 中用颜色填充一个圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920478/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4