Rendering shadow sprites in cocos2d-x

Posted by lukeluke on Game Development See other posts from Game Development or by lukeluke
Published on 2011-12-10T17:09:34Z Indexed on 2012/04/11 23:46 UTC
Read the original article Hit count: 813

Filed under:
|
|

I am writing a 2D game with cocos2d-x. I want to put a "shadow" sprite on a background sprite using the equation:

MAX(0, Cd*1 - Cs*S)

where Cd is the destination color (that is, a background pixel), Cs is the source color (the shadow pixel) , S is the scale factor (between 0 and 1). The MAX() function is used to avoid negative results. This is a lighting effect: when the shadow sprite pixel is 0, there is no effect on the background pixel, otherwise, the background pixel becomes darker.

Now, the only way that comes to my mind is to change the blending equation to GL_FUNC_SUBTRACT, but it doesn't compile with cocos2d-x (can't found it)...

I would subclass the CCSprite class in order to implement the draw() method in order to change, when needed, the blending equation, call the original draw() method and restore the blending equation to its previous state at the end of the method.

So my questions are two:

  1. how to use glBlendEquation() with cocos2d-x? Keep in mind that i am writing a game for iphone/android/windows.
  2. are shadows handled this way in 2D games?

Thx

© Game Development or respective owner

Related posts about sprites

Related posts about cocos2d