2013-02-17 95 views
2

我使用cocos2d的,我畫圈圈這樣填充顏色的圓圈在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方法,但也只圓的界限變得顏色。

所以我的問題是如何用顏色填充一個圓圈,我錯過了什麼?

+1

或http://www.cocos2d-iphone.org/forum/topic/32127一個看似簡單的解決方案 – 2013-02-17 11:17:33

+1

@MilKyWaY它有一個回答十六票! – 2013-02-17 11:25:04

+0

使用CCDrawNode如果你在cocos2d 2.1 – LearnCocos2D 2013-02-17 12:39:52

回答

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 [email protected] 
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);   
} 
} 
1

謝謝你們!我沒有想過要更換cocos2d代碼來完成我的工作,我不知道這是否正確,但它對我有用!

隨着Rachel Gallen的迴應。我去CCDrawingPrimatives.m和改變

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

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

和它的工作。

+0

歡呼!高興地幫助:) – 2013-02-17 11:33:37

+0

@RachelGallen我可以添加透明度嗎? – ddarellis 2013-02-17 11:44:06

+0

你的意思是你想把不透明度降低或者你想混合兩個圓圈?我只是讓我的午餐在一分鐘後會有一個咕嚕嚕 – 2013-02-17 11:53:36