Hello cocos2d- community,
I would like to cut out an image of another image. So i would like to set a bullet sprite over a target and than cut it out. On the position should be a hole in the target and the background is visible.
My application consist of following sprites:
+) Background Sprite (z:-3)
+) Target Sprite (z:-2)
+) Bullet Hole Sprite (z:1)
I add the background and target sprite to my layer. With every touch i create the bullet hole on the touch position. After i add the sprite i add this line right under it:
[bulletHole setBlendFunc:(ccBlendFunc){GL_ZERO, GL_ONE_MINUS_SRC_ALPHA}];
I upload two screenshots to get a better illustration of the problem.
First:
You can see the background and target Sprite:
Second:
You can see the bullet hole that cuts out the target sprite:
So here is the problem! The blendfunc works perfect - it cuts a hole in the target sprite but also in all other sprites that are at the layer. I only would like to cut a hole into the target sprite. So i can see all other sprites behind/through it.
I tried to create a background layer and add the target layer to it. The target layer includes the touch method to set the bullet hole.
This solution also dont work and i got the same effect with one layer.
So i think that i have another solution but i dont know how to do it:
1) allow the blendFunc only on two sprites (target sprite and bullet hole sprite)
2) make a screenshot and set the black area to transparency
Have a nice day,
whoop