• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 在 cocos2d 中用颜色填充一个圆圈

[复制链接]
菜鸟教程小白 发表于 2022-12-13 01:09:13 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我用 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap