0
votes

I need to mask a sprite. I followed this tutorial: http://www.raywenderlich.com/4428/how-to-mask-a-sprite-with-cocos2d-2-0 , however the problem is when I create sprite not from single png file, but from sprite sheet with "initWithSpriteFrameName" method.

The mask file is beying applied to the big sprite sheet's texture, instead of the small sprite's texture.

Any clues how can I fix this?

Cheers, Marcin

1

1 Answers

2
votes

The problem here is that the same tex coords are being used for your sprite and your mask.

You need to send through two more UV coordinates per vertex, which fit your mask in the atlas.

Create another varying, v_maskTexCoord, for these mask coordinates, and then where you do this:

vec4 texColor = texture2D(u_texture, v_texCoord);
vec4 maskColor = texture2D(u_mask, v_texCoord);

Change it to

vec4 texColor = texture2D(u_texture, v_texCoord);
vec4 maskColor = texture2D(u_mask, v_maskTexCoord);