我对所有这些 OpenGL 调用都很陌生,但幸运的是 cocos2d 可以轻松让我在屏幕上画线,如下所示:
I am very new to all those OpenGL calls, but fortunately cocos2d will easily let me draw lines on the screen, like this:
-(void)draw {
glColor4f(255, 255, 255,255);
ccDrawLine(ccp(150,110), ccp(280,230));
}
我得到一条白线.
但是现在,我想让它变得有点透明,所以我将 alpha 值更改为 100.但是,这条线仍然是亮白色的.然后我假设这些值实际上可以在 0.0 到 1.0 之间.我将它设置为 0.2 但仍然没有变化.
But now, I want to make it a bit transparent, so I change the alpha value to 100. However, the line is still bright and white. Then I assumed that the values could actually range from 0.0 to 1.0. I set it to 0.2 but still no change.
这是为什么呢?
你肯定需要先启用混合:
You definitely need to enable blending first:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4ub(255, 255, 255,100);
ccDrawLine(ccp(0,110), ccp(280,230));
另请注意,glColor4ub"采用无符号字节(每个参数为 0-255),而"glColor4f" 接受 4 个浮点数(每个参数为 0-1.0).使用任何你觉得舒服的.
Also note that "glColor4ub" takes in unsigned bytes (0-255 for each parameter) while "glColor4f" takes in 4 floats (0-1.0 for each parameter). Use whichever you are comfortable with.
祝你好运!
这篇关于ccDrawLine 不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!