Search code examples
iosscrollviewcocos2d-xtexture2d

In cocos2dx, I use RenderTexture to capture the screen, but images in scrollview are lost


After I capture the screen with:

auto renderTexture = RenderTexture::create(width, height,Texture2D::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8_OES);
Scene* curScene = Director::getInstance()->getRunningScene();
renderTexture->begin();
curScene->visit();
Director::getInstance()->getRenderer()->render();
renderTexture->end();

The images and texts in the scrollview which are outside of the screen are lost like this: 1. normal image The bottom is outside of the screen

the result after capture screen


Solution

  • The engine would culling the sprite out of screen(at function Sprite::draw) to get higher performance. You can either close it by modifying the macro CC_USE_CULLING(at file cocos/base/ccConfig.h, or you can move the objects in the screen when you capture the screen and move them back after render finish.