How to get a screenshot in cocos2dx-3.0 rc0

How to get a screenshot in cocos2dx-3.0 rc0
0.0 0


1,save a screenshot

Size s = Director::getInstance() -> getWinSize();
auto renderTexture = RenderTexture::create(s.width, s.height, Texture2D::PixelFormat::RGBA8888);
renderTexture -> begin();

2, get you saved screenshot
std::string fileName = FileUtils::getInstance()->getWritablePath() + “coco2d-x-screenshot.png”;
auto sprite = Sprite::create(fileName);
sprite->setPosition(Point(40, 40));

How to use "Opengl Shader" in cocos2d-x3.0

Hi yuye,
Thank you!! it’s always nice to know this…
I have a problem can you help me out?



Thanks @yuye

Can we use this to make a video( say 24fps) out of the screenshots?
Also, is there a way to record the sound for playback?


@indygamer you just can record it by youself。


i wouldn’t recommend you to make a video, its going to slow your game down significantly


@yuye @Wuhao

The video playback is a feature of the game. It is not for a explainer video or a gameplay video.

It is for in game - video playback feature where players can rewind and watch their gameplay.

Is this possible (without slowing down game) via screenshot approach via CCDirector save image.

Alternatively, I can record the player input moves in a stack and re render the scenes during rewind.

I want to generate the slow motion video playback of the users gameplay in reverse direction while rewinding - like in a movie playback.


the best way to implement replays is to re-run the game

-you must use fixed update delta time,
-you must modify you random number to seeded random number, and use the same seed


Hi Yuye,
Could you please help, following code is not working ,i am using cocos2dx 3.0 -> here is the code. I think problem is with opengl portion , may be i am doing it wrong …

RenderTexture* rt = RenderTexture::create(textureWidth, textureHeight);
rt->beginWithClear(color.r, color.g, color.b, color.a);

float gradientAlpha = 0.7f;
Point vertices[4];
Color4F colors[4];
int nVertices = 0;

vertices[nVertices] = Point(0, 0);
colors[nVertices++] = Color4F(0, 0, 0, 0);
vertices[nVertices] = Point(textureWidth, 0);
colors[nVertices++] = Color4F(0, 0, 0, 0);
vertices[nVertices] = Point(0, textureHeight);
colors[nVertices++] = Color4F(0, 0, 0, gradientAlpha);
vertices[nVertices] = Point(textureWidth, textureHeight);
colors[nVertices++] = Color4F(0, 0, 0, gradientAlpha);

// Set the shader program for OpenGL

glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);

Sprite* noise = Sprite::create("Noise-hd.png");
BlendFunc blendFunc;
blendFunc.src = GL_DST_COLOR;
blendFunc.dst = GL_ZERO;
noise->setPosition(Point(textureWidth / 2, textureHeight/2));
Sprite* sprite = Sprite::createWithTexture(rt->getSprite()->getTexture());
return sprite;