Getting screenshot

Getting screenshot of currently showing scene:

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

Creating a sprite from RenderTexture:

auto sp= Sprite::create();
sp->initWithTexture(rt->getSprite()->getTexture());
scene->addChild(sp);

Saving screenshot to a file:

rt->saveToFile(filePath);