views:

94

answers:

1

Hi!

Is there way to do the shadow for CCSprite?

Thanks, Yakov

+1  A: 

Well, you essentially have two options:

1) Bake the shadow into the sprite images themselves, or 2) Manage the shadow as a separate sprite.

The former approach is easiest. Open your sprite up in Photoshop, set the layer to have a drop shadow, and then save it back out. This will only work if you have a consistent light source and don't go rotating or flipping the sprite in a way that puts the shadow in the wrong place.

Otherwise, you can manage two sprites: your normal sprite, and a shadow sprite. You don't need new graphics for this, probably. Instead, you can use the same texture and just set the color of the sprite to black using:

 sprite.color = ccc3(0,0,0);

You might also try:

 sprite.opacity = 128;
 sprite.scaleY = -1.0;

This shouldn't incur too large a performance hit, since you can grab it from the same texture. If you match the animation frames of the shadow to those of the original sprite, the shadow will even match.

cc