Cocos2dx Android I'm broken phenomenon after the launch is an image sprite onResume Activity

梦想与她 提交于 2019-12-24 11:44:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!