ccDrawLine opacity?(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 不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ccDrawLine 不透明度?


基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01