Search code examples
androidc++cocos2d-x

Painting texture in cocos2d-x


I am working on a baby app and there is a Bath scene in which user applies soap to the baby's body. That is he drags the soap bar over the body like painting and soap bubbles appear on the body wherever the soap is applied like painting soap texture with a brush (soap bar).

I have the soap bar sprite and the texture sprite and the baby sprite.

How can I achieve an effect like that ?

Edit: So I have this bubbles sprite. And I want wherever the user touches, the opacity of that point in the sprite becomes 1 or 255. In start the opacity would be zero so it won't be visible and when the user drags the soap over the baby's body the opacity will become 255 for every point the user drags the soap over.

Here see the soap bubbles sprite


Solution

  • I think you could achieve this the following way:

    1. Place your "baby with bubbles" in a CCLayer (as a sprite). This will be the background.
    2. Create a second layer in front of the first and put a CCTexture2D into it, filled with white.
    3. Whenever the user touches the screen, at that point, draw the brush sprite into the texture. The brush sprite must draw with transparency.

    This reference may help.

    Was this helpful?