Hello. Could you help me with creating transparent area in a texture. I’ll explain. I have one large sprite. I should create a transparent hole in it. How can I to do it. Thanks.
Use a file format that supports transparency (like png) and set the required area to transparent.You don’t have to do anything in your code to make it work.
Adam Reed wrote:
Now, I do not know how to realize it. Should I use openGL or Cocos functions? Thanks in advance.
When I say change your image I mean use GIMP or Paint.Net or any other package that supports png.
cocos2d supports transparency out of the box so you just need to change your base image to add transparency.
I have all graphics in png format. I’ll will try to add transparency. Thank you very much for helping and your idea.
Mmmm. I’ve tried to find methods for working with transparency. And it was unsuccessful. Maybe I should use openGL functions ?
I’m not sure what you mean.
Does your png have transparent sections?
Sorry for explanation. My target sprite in png format. But I need to do transparent area on it after touch. My actions: I calculate positions for touch and size transparent hole. After, in runtime I need edit current texture. And I did not find solution.
Now I understand.
CCSprite has a function getTexture that returns a CCTexture2D.It also has a setTexture that accepts a CCTexture2D.
I’m not sure if you can do what you want to a CCTexture2D.There are 2 functions, drawAtPoint and drawInRect
Have a look in http://www.cocos2d-x.org/embedded/cocos2d-x/d7/dfd/classcocos2d\_1\_1\_c\_c\_texture2\_d.html
Thanks for idea. Unfortunately I’ve not found correct applying this methods. Is there solutions with using openGL or blending methods?
So you got a sprite and after user touches it you want to make part of this sprite transparent so it looks like there is a hole in it. There should be something for this in OpenGL if you want to use that method. You could try searching this forum or google. Other way to accomplish this could be something like this… create a CCImge with this image that you want to make holes in it and when user touches the sprite then you make a hole in CCImage using raw pixel data (CCImage has getData method that returns pointer to pixel data) and then after you edit pixels of CCImage (note that there are no functions to blend images or cut holes in it etc. so you will need to write it by yourself) you update your sprite with this CCImage.