ccDrawLine 不透明度? [英] ccDrawLine opacity?

查看:37
本文介绍了ccDrawLine 不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对所有这些 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 不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆