感谢社区会员tuyuer的无私贡献
论坛里有为大神实现了水果忍者的1.x版的刀光效果,
小弟在此尽心了修改,使其可以运行在cocos2dx-2.x版,欢迎指正。
请先找到Drawline.cpp文件,论坛里有1.x的刀光,请自己找到下载
此处为1.x版。
// glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// glDisable(GL_TEXTURE_2D);
//
// glVertexPointer(2, GL_FLOAT, 0, vertexTriangle);
// glEnableClientState(GL_VERTEX_ARRAY);
// glColorPointer(4, GL_UNSIGNED_BYTE, 0, lineColors);
// glEnableClientState(GL_COLOR_ARRAY);
// glDrawArrays(GL_TRIANGLES, 0, (GLint)((vertexCpy-vertexTriangle-1)));
//
// glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// glEnable(GL_TEXTURE_2D);
//以下两行可以放到初始化方法中
CCGLProgram * glShaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionColor);
this->setShaderProgram(glShaderProgram);
//以下代码为上面代码的2.0版本
// Enable the needed vertex attributes.
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_Color );
// Tell OpenGL ES 2.0 to use the shader program assigned in the init of this node.
this->getShaderProgram()->use();
this->getShaderProgram()->setUniformForModelViewProjectionMatrix();
ccVertex2F vetexes[512]={0};
for (int i=0; i<512; i++) {
vetexes.x=vertexTriangle.x;
vetexes.y=vertexTriangle.y;
}
// Pass the verticies to draw to OpenGL
glEnableVertexAttribArray(kCCVertexAttribFlag_Position);
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_TRUE, 0,vetexes);
// Pass the colors of the vertices to draw to OpenGL
glEnableVertexAttribArray(kCCVertexAttribFlag_Color);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, lineColors);
GLint numberTo=(GLint)((vertexCpy-vertexTriangle-1));
glDrawArrays(GL_TRIANGLES, 0,numberTo );