CCRenderTexture and z order

Hello,
I render my game screen to texture by CCRenderTexture. I do this in visit(), which I use for standart rendering.
So only difference is change buffers for render.

cocos2d::CCRenderTexture* m_pOffScreen;
m_pOffScreen = CCRenderTexture::renderTextureWithWidthAndHeight((int) s.width, (int) s.height);
m_pOffScreen->retain();
m_pOffScreen->setPosition(ccp(s.width / 2, s.height / 2));

void GameScreen::visit()
{
    if (mRenderToTexture)
    {
        m_pOffScreen->begin();
    }

    LSScreen::visit();

    if (mRenderToTexture)
    {
        m_pOffScreen->end();
        mRenderToTexture = false;
        m_game_ui->setIsVisible(true);

        mScreenShotNumber++;
        std::string screenShotName = "img" + LSUtils::intToString(mScreenShotNumber) + ".png";
        m_pOffScreen->saveBuffer(kCCImageFormatPNG, screenShotName.c_str());
        LSDevice::saveImageToGallery(screenShotName);
    }
}

But in rendered image its wrong z-order (see screenshots).

For rendering we use bachnodes and setting z-order by setVertexZ().

(In this time is not possible to add file. I do it later.)


standart_render.png (920.9 KB)


to_texture_render.png (892.4 KB)

So nobody has this problem?

I don’t have this problem, but I sort all my sprites on the zOrder. I don’t use vertexZ. You may want to try that, reordering on Z is very efficient now too.

Z Order depends on the parent node, so ideally they’ll share a parent node to honor it. But if you did have them broken up, you can still layer the drawing and draw it ok, such as.

MyBaseBackgroundBatch->setZOrder(-1); MyHousesBatch->seZorder(10); MyCharactersBatch->setZOrder(20);

One thing to remember is that each batch is a parent. So if you have a house on your MyHouseBatch node, at Z 3000, the sprites on MyCharacterBatch will still lay on top of it. Because that 3000 is just in that batchnode, but on the main layout the MyCharactersBatch is a higher Z than the myHouseBatchNode.

I hope that makes sense. With this layout you can have some good flexibility.