如何在 cocos2d 中点亮一个精灵? [英] How to light-up a sprite in cocos2d?

查看:26
本文介绍了如何在 cocos2d 中点亮一个精灵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何通过以下方式使 CCSprite 对象变暗:

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

sprite.color = ccc3(x, x, x);//x 是小于 255 的值

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

(据我所知,应该是openGL函数的直接映射,所以很容易实现.)

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

但是当涉及到点亮时,我当前的解决方案是添加另一个蒙版精灵(形状相同,但全部为白色),将其 blendFunc 更改为 { GL_SRC_ALPHA, GL_ONE } 并将其覆盖到目标上.除了添加的所有代码之外,每个需要点亮的代码都应该有一个掩码图像.

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?

推荐答案

不过,没有setColor那么简单,在Cocos2d 2.x中,有了OpenGL ES 2.0的支持,你可以通过使用自定义着色器来实现.您可以从这里开始:http://www.raywenderlich.com/10862/how-to-create-cool-effects-with-custom-shaders-in-opengl-es-2-0-and-cocos2d-2-x

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.

这篇关于如何在 cocos2d 中点亮一个精灵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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