How to light-up a sprite in cocos2d?

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I've already know how to dark-down a CCSprite object by:

sprite.color = ccc3(x, x, x); // x is a value less then 255

(As far as i know, it should be a direct mapping of openGL functions, so its easy to achieve.)

But when it comes to light-up, my current solution is adding another mask sprite (same shape but all in white), changing its blendFunc to { GL_SRC_ALPHA, GL_ONE } and overlaying it onto the target. Besides all the codes added, there should be a mask image for each need-to-light-up one.

Is there a way to do light-up as easily as dark-down?

回答1:

However, not as easy as setColor, in Cocos2d 2.x, with OpenGL ES 2.0 support, you can achieve this by using custom shaders. You can get started here: http://www.raywenderlich.com/10862/how-to-create-cool-effects-with-custom-shaders-in-opengl-es-2-0-and-cocos2d-2-x

You may also try inverting the sprite's darker color to get a lighter one.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!