In my game, I started drawing several gradients and using them as background. That worked fine with Android, but when I tested with Lumia 435 it lagged horribly.
Is the texture created using the RenderToTexture example stored in TextureCache by default? If not, how should I add it? RenderTexturert->getSprite()->getTexture() returns a Texture2D pointer but Director::getInstance()->getTextureCache()->addImage() only accepts a filename or a cocos2d::Image
Looks like RenderTexture has the functionality you’re wanting disabled:
void RenderTexture::listenToBackground(EventCustom *event)
{
// We have not found a way to dispatch the enter background message before the texture data are destroyed.
// So we disable this pair of message handler at present.
I think you have two viable options:
Add the texture manually to VolatileTextureMgr (Texture2D will remove itself automatically on destruction)
Write your texture to file after rendering and then use that texture by file name to create a sprite which will be added to the texture cache automatically. This approach can serve as a good optimisation if you want to release the texture from memory and obtain it later without the overhead of regenerating it, but has the cost of writing it to file in the first place.
If you need a simple gradients for background, don’t draw it. You don’t need renderTexture either.
create a 1/10 size gradient image in photoshop or etc and scale it 10X.
There is no penalty for performance and quality.
Try it.
@almax27 haven’t been able to find VolatileTextureMgr help in cocos2d-x v3.10 API reference maybe it has been deprecated?
Anyway, a mate already pointed me out the solution given my @amin13 (thanks @amin13 btw), just wanted to be sure if there were another way to solve my problem as I do find easier for testing purposes to change RGB values, compile and run rather than create texture, save, copy to resources and run.
So, if I load all my textures from files (either using a plist or direct png files) and use them in sprites, , will them be reloaded if my app loses focus and gains it later again?
VolatileTextureMgr is defined in CCTextureCache.h, it is used for rebuilding your textures when the GL context is destroyed. It is very much not deprecated perhaps it’s not in the API reference because it does not have any documentation comments.
Ultimately if you don’t intend to change the texture at run time (colour, angle, offset of the gradient), and you’re unlikely to need many variations, then using packaged assets definitely makes more sense. Generating the gradient at runtime does afford you the benefit of reducing your apps download size though