Clipping CCNode

Here is a port of a Cocos2d clipping node for Cocos2d-x 2.0.2

Enjoy!

Usage:

//create ClipNode and add to main node
node=new ClipNode();
node~~>autorelease;
node~~>setPosition();
node~~>setClipsToBounds;
node~~>setScale(…);
addChild( node);

//add sprite to it

//define clipping region
node->setClippingRegion(CCRect(x,y,w,h)); //in Points


ClipNode.zip (1.9 KB)

Thank you for sharing with us. ClippingNode is very useful.

@RicardoSilva Thanks a lot

Just noticed that in the header file I wrote that the scissorRect is in pixels, but it’s in point!

Hi, thanks, indeed it is very useful.

However, when I push a CCTransition* scene on the container scene, I noticed that all the children get animated (transitioned), but the Clip Rect is not transitioned. Any idea how to transition the clip rect as well?

Thanks!

It seems like the stencil node gets rendered too if I’m putting SpriteBatchNode as the child of ClippingNode. Is there a way to fix it?

Herman To wrote:

It seems like the stencil node gets rendered too if I’m putting SpriteBatchNode as the child of ClippingNode. Is there a way to fix it?

What do you mean? So you are using a SpriteBatchNode?

Solved, I mistakenly added the mask to the root node also, so it gets rendered.