cocos2dx .3x精灵灰色 官方太吭。老子研究10年,老子教你们怎么变灰。终于可以装B了

在Sprite 多个变量 m_bGray 并构造初始化为false

在多个函数直接上代码。官方什么东西都吭,我带你们飞(终于可以装B了,研究了4五天)

void Sprite::setGray(bool bGray)
{
if (m_bGray == bGray)
return;

m_bGray = bGray;

if (bGray)
{
     GLchar* pszFragSource =
     "#ifdef GL_ES \n \
     precision mediump float; \n \
     #endif \n \
     uniform sampler2D u_texture; \n \
     varying vec2 v_texCoord; \n \
     varying vec4 v_fragmentColor; \n \
     void main(void) \n \
     { \n \
     // Convert to greyscale using NTSC weightings \n \
     vec4 col = texture2D(u_texture, v_texCoord); \n \
     float grey = dot(col.rgb, vec3(0.299, 0.587, 0.114)); \n \
     gl_FragColor = vec4(grey, grey, grey, col.a); \n \
     }";

     CCGLProgram* pProgram = new CCGLProgram();
     pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_noMVP_vert, pszFragSource);
     this->setShaderProgram(pProgram);
     pProgram->release();
     CHECK_GL_ERROR_DEBUG();

     pProgram = this->getShaderProgram();
     pProgram->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
     pProgram->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
     pProgram->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);
     CHECK_GL_ERROR_DEBUG();

     pProgram->link();
     CHECK_GL_ERROR_DEBUG();

     pProgram->updateUniforms();
     CHECK_GL_ERROR_DEBUG();

}
else
{
     setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
}

}
:6::6::6::6::6::6::6::6: 福利拿走吧!

官方真是吭啊,Button点击当normal的时候是单个放大不是集体放大。又研究了个1下午终于集体放大了。各种吭,各种埋雷。:8::8::8::8::8::8::8:

雷区,慎入!

2.X 时代已去

这是3.x代码 不是2.x:11:

教你们怎么使用

在引擎中 Sprite类中声明个 m_bGray 变量 构造出false
在sprite声明个函数 void setGray(bool bGray);
函数定义在楼顶

auto *pSprite = Sprite::create(路径);
pSprite->setGray(true); // 灰色
再次pSprite->setGray(false); // 还原
:11:

— Begin quote from ____

引用楼主硬币于2014-10-11 11:54发表的 cocos2dx .3x精灵灰色 官方太吭。老子研究10年,老子教你们怎么变灰。终于可以装B了 :
在Sprite 多个变量 m_bGray 并构造初始化为false

在多个函数直接上代码。官方什么东西都吭,我带你们飞(终于可以装B了,研究了4五天)

http://www.cocoachina.com/bbs/job.php?action=topost&tid=234144&pid=tpc

— End quote

!
我想问下u_texture这个变量在哪来设置了,我在引擎里面没找到设置的,只看到const char* GLProgram::UNIFORM_NAME_SAMPLER = “CC_Texture0”;
)

雷区,用了之后直接闪退。。我3.2的版本 而且精灵也不是灰色 是黑色。

我是3.1版本, 3.2究竟改了什么,我也不知道。:8:

GLchar* pszFragSource 字符串里面自己研究, :14:
其实我也不懂,半学半懂。

具体需要怎么做呢 帮忙贴一下代码呗 谢谢

一个破灰图还要搞个4,5天, 这b装大了