2

私は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);
}

これはボールが動かせるように中心を大きくした状態です。これは赤い境界線の円を生成しますが、円を色とアルファで塗りつぶしたいと思います。

また、CCSprite クラスをサブクラス化して呼び出してみました

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

init メソッドですが、ここでも円の境界線のみが色になります。

私の質問は、円を色で塗りつぶす方法です。何が欠けていますか?

4

2 に答える 2

2

不透明度を設定するには、これを試してください

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);        
}
}
于 2013-02-17T12:05:57.817 に答える
2

君たちありがとう!自分の仕事をするために cocos2d コードを変更しようとは思いませんでした。これが正しい方法かどうかはわかりませんが、うまくいきました。

レイチェル・ガレンが言及したように。CCDrawingPrimatives.m に行って変更しました

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

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

そしてそれはうまくいきました。

于 2013-02-17T11:30:01.033 に答える