cocos2d/cocos2d-iphone — pull request #231 by krzysztofzablocki (2012-08-20 08:25:56+00:00)
Title: Rendering Target Node - Rendering to texture made simpler.

Problem
CCRenderTexture is abused by many people, people get confused how to render properly into it, like overriding visit methods, mostly because not all cocos nodes are easy to use with CCRenderTexture:

* CCSpriteBatchNode cannot be visited if it's not inside scene tree, if you add it to scene tree and then call [batch visit] between begin and end of RenderTexture rendering you are rendering twice. That's just wrong. You could 'fix' it by hiding the batch at start and then make it visible just before visiting it inside your renderTexture redraw. I still believe that's far from nice solution.

* Animations are _paused if nodes are not in scene node, again could be 'fixed' as in previous point.

'fixed' - means workaround and in my book is really poor.

Solution
Added CCRenderTargetNode - a node that simplifies rendering into CCRenderTexture.

* Whatever you add into it, will be rendered into CCRenderTexture and only there.

* Animations will work since it's it will be in scene tree, batches will work as well. Also no hacking required to work with them.

* CCRenderTexture has lazy created .renderTargetNode property that can be used for adding renderTexture content nodes into it, they will be rendered into RenderTexture and only there.

* ( Also it could be used to render into CCRenderTexture that's not in scene tree ( if you'd need that kind of functionality ), you can plainly create it with RenderTexture but you need to retain RenderTexture by yourself so that it doesn't get released before this node. )