ios - 在 cocos2d 中用颜色填充一个圆圈
<p><p>我用 cocos2d 画这样的圆圈</p>
<pre><code>- (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);
}
</code></pre>
<p>这是球的一种状态,我增加中心使其可以移动。
这会产生红色边框圆圈,但我想用颜色和 alpha 填充圆圈。</p>
<p>我也尝试子类化 CCSprite 类并调用</p>
<pre><code>self.color = ccc3(200 / 255.0f, 0 / 255.0f, 0 / 255.0f);
</code></pre>
<p>在 init 方法中,但同样只有圆圈的边框有颜色。</p>
<p>所以我的问题是如何用颜色填充一个圆圈,我错过了什么?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>设置不透明度试试这个</p>
<p>来自 <a href="http://www.cocos2d-x.org/boards/6/topics/5868" rel="noreferrer noopener nofollow">http://www.cocos2d-x.org/boards/6/topics/5868</a> </p>
<pre><code>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);
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 在 cocos2d 中用颜色填充一个圆圈,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14920478/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14920478/
</a>
</p>
页:
[1]