Cocos2D: How to use Mask Image

1.8k Views Asked by At

I am using cocos2d for a game which uses sprite sheets for my character animations. I created these images using TexturePacker. Now, I want to use PVRTC 4 format for reducing memory consumption due to some reasons. But as the PVRTC Texture Compression Usage Guide suggests, I need to add extra border of 4 pixels in each character to produce proper results. Even if I add border, I will have to mask this image with alpha image to remove border at run time. I am using Texture Packer to create a sprite sheet with PVRTC4 format and created alpha masking image matching it. I am ready with these 2 images in hand which are of same width and height.

Now my question is, how can I mask my PVRTC texture with alpha image in Cocos2D?

It will be more helpful if the solution provided works with Batch Nodes!

Thanks in advance for any solutions!

2

There are 2 best solutions below

4
On

Why don't you just make the border/padding area completely transparent?

0
On

I was having the same problem, and after reading ray wenderlichs page about masking, I made a little ccsprite subclass which allows you to mask by 2 images.

CCMaskedSprite