CCClippingNode in complex situation


I am trying to achieve some kind of night effect with enemies carrying flashlights.
To do so, I have basically 2 layers of my level, one in front for the night, and one beneath it for the day. Then, I would like to carve holes in the night layer by using clipping nodes. So the day layer could appear were there is supposed to be light.

Here is my hierarchy :

ClippingNode (night)
|  |-Scenery node 1
|  |-Scenery node 2
|  |-Scenery node 3
|-STENCIL (inverted)
   |-ClippingNode (lightedArea 1 - the light circle minus the shadows)
      |  |-DrawNode (Flashlight white soft aliased complete ring)
      |-STENCIL (inverted)
         |-DrawNode (cast shadow raytracing)

The thing is, the Night ClippingNode never gets clipped. It appears on the entire screen… If I add the LightedArea nodes to the Night node content instead of the stencil, it appears that white illuminated areas are computed just as I expect them to be.

Here are 2 screenshots.

  • On the first one, lightedAreas are added as children of the night Stencil, and when I do so, the Night clippingNode doesn’t get carved (that is my issue)

  • On the second one, I added the exact same lightedAreas directly as content of the ClippingNode I use for the night.

  • I was expected the white areas visible on screenshot 2 to carve holes in my Night ClippingNode (clipping is reverted). Why doesn’t it behave like this ? Am I expecting too much from the ClippingNode or am I doing something wrong ?

WallGridz - 480x320 - 1.png (68.3 KB)

WallGridz - 480x320 - 2.png (67.8 KB)


In other tests, something appeared strange to me… Is the coordinate referencial somehow different for my drawings rather I use the resulting CCDrawNode as mask/stencil for a CCClippingNode or I display it directly ?
Because I tried 2 things :

  • drawing concentric circles, using drawDot, in a drawnode used as mask results in a cone shaped hole. Like if the offset is 0, 0 rather than the dot center position ;
  • drawing 2 big wide segments accross the entire screen (top-left to bottom-right and bottom-left to top-right) gives me only 1 segment visible as a mask, and that segment is narrower that it should…

These odd results appear as long as you set an alpha threshold different from 1.

If these examples don’t make sense written down like this, I’ll try to get some screenshots of my results as well.


I am still trying various stuff to get the effect I would like to get. So far nothing seems to work for me :frowning:
The latest I tried is a much simpler setup as what I described in the first post. But, apparently, using CCDrawNodes will work as stencils for a CCClippingNode only if the alpha test is disabled. As soon as I set an alpha threshold different from 1, the masking seems broken… Has anyone information about that ?


Still trying new things here…

Now I am trying to render things using CCRenderTextures. Seems to solve my CCDrawNode versus alphaized CCClippingNode issues ! So I think I finally won a battle :slight_smile:
But I still have a problem… Now I’m trying to render things with 1 CCRenderTexture as stencil for my main layer. On this texture I actually render (through visit() ) a list of other CCClippingNode instances. And in this configuration, there is no transparency… Stencil areas where I didn’t draw anything appear white, as if default alpha is then 1 instead of 0.

Would someone eventually have any idea to help me ?