Example usage of RenderTexture in Cocos-Creator

Example usage of RenderTexture in Cocos-Creator
0.0 0


Can someone provide an example of how to use rendertexture in cocos-creator.
Like how to render a list of labels into a texture.?

Couldn’t find any examples that work. Tried the below code, but does not work.

 var renderTexture = cc.RenderTexture.create(200,200);
renderTexture.beginWithClear(0, 0, 0, 255*0.9);
var spriteComp = this.node.getComponent("cc.Sprite");
spriteComp.spriteFrame._texture = renderTexture._texture;


Vote + for working example of RenderTexture

I have to trying render my Game Layer on RenderTexture and apply post-effects on them. But its rly slow on my implementation.

How to disable render on screen of Game Layer and render only RenderTexture with texture of rendered game layer?


Check out this demo project with my own implementation of RenderTexture and some shaders. Only works on html5 builds though.


Does cocos-creator not support the same in native?


I don’t know, cc.RenderTexture looks like some cocos2d-js left-over actually :slight_smile:
I just shared my implementation of somewhat similar techinque we used for scene post-processing in a big html5-only project.


@pandamicro any idea?


Its been sometime since you post but I will just try answer it anyway…

Instead of directly appending it as a Sprite Frame, create it with proper size might help

var texture = rt.getSprite().getTexture();
var size = texture .getContentSize();
var sf = new cc.SpriteFrame(texture,cc.rect(0,0,size.width,size.height),false,cc.p(0,0),cc.size(size.width,size.height));

spriteComp.spriteFrame = sf;