问题
CCTexture2D *t = new CCTexture2D();
t->initWithData(imageData, kCCTexture2DPixelFormat_RGBA8888, sprite->getTexture()->getPixelsWide(), sprite->getTexture()->getPixelsHigh(), sprite->getTexture()->getContentSize());
CCSprite *ret = CCSprite::createWithTexture(t);
In this way, only the title and sprite-like phenomenon is created.
CCSprite *ret the effect of the water on the Beach the Sprite to customize the image. IOS, Android, without any problems, the onPause ()-> onResume (a) through Ret image turns black
How to solve it?
回答1:
Any sprite that was not loaded from file becomes black after resuming, either CCTexture2D initialized with data or CCRenderTexture.
Easiest solution: stop using dynamic textures, load all textures from files.
Workaround: Resume event callback placed in your cocos2d::CCApplication subclass - it's method applicationWillEnterForeground(). You can manually reload all textures inside this method. For example, create own interface A that have virtual method to reload child textures, and manager class B which keeps global list of A. A registers itself in B in constructor and unregisters in destructor.
In each class that uses dynamic textures (i.e without file representation), implement interface A and override method in order to reload all dynamic textures.
回答2:
Even i faced the same problem. You need to make changes in CCPlatformMacros.h, Cocos2dxGLSurfaceView.java and main.cpp( in you jni folder).
You should go throught this for detailed changes https://github.com/cocos2d/cocos2d-x/pull/2384.
来源:https://stackoverflow.com/questions/16726426/cocos2dx-android-im-broken-phenomenon-after-the-launch-is-an-image-sprite-onres