Hi everyone,
I’ve been trying to upgrade some 3.17 projects to v4.0 and I’ve encountered the following problem. What the code is trying to achieve here is, capturing a screenshot of my app and then rendering it in another renderTexture, which is used to perform some free-hand drawing.
To explain why I need to do this, the initial setting is as follows:
Background Sprite → renderTexture used as blackboard which is transparent, except for the lines drawn with screen touches.
From this initial setting, with a button touch, I want to pass in another one which is kinda like this:
Different background Sprite → renderTexture fully opaque comprising of a “screenshot” of the drawing I made and the previous background
This way, when I “erase” from my renderTexture I can gradually reveal the second, different background Sprite.
The code for the first part, capturing a screen using a renderTexture is pretty straightforward:
RenderTexture *tex = RenderTexture::create(**int**(screenSize.width), **int**(screenSize.height), PixelFormat::RGBA8888);
tex->setPosition(Vec2(screenSize.width/2, screenSize.height/2));
tex->begin();
background->visit();
blackboard->visit();
tex->end();
tex->retain();
I was wondering what would be the best way to feed this image to the renderTexture which functions as a blackboard. The code already present, which was working fine in 3.17 was:
Image img = tex->newImage();
Texture2D tex2d = new Texture2D();
text2d->initWithImage(img)
Sprite* spr = Sprite::createWithTexture(tex2d);
spr->setAnchorPoint(Vec2(0,0));
spr->setPosition(Vec2(0, 0));
renderTexture->begin();
spr->visit();
renderTexture->end();
But this doesn’t seem to do anything at all in v4, leaving me with the “blackboard” renderTexture unchanged. Another, simpler way to do the same would seem to be
Sprite* spr = Sprite::createWithTexture(tex->getSprite()->getTexture());
renderTexture()->begin();
{
spr->setAnchorPoint(Vec2(0,0));
spr->setPosition(Vec2(0, 0));
spr->visit();
}
renderTexture()->end();
Which however does not maintain the lines that I have previously drawn.
Could anyone hint me as to why this doesn’t work as in v3.17?