Recently encountered a COCOS2DX bone animation registration event playback sound effects, when the bone animation playback, press the home button to return to the desktop, when the game is opened again, will be black screen.
The solution is as follows, probably not too perfect, at least to solve most of the problems.
1. Add the native method to the Cocos2dxrenderer.java under Org.cocos2dx.lib
Public Static native void Setispause (boolean ispause);
2. Add the corresponding method in the Cocos2dxrenderer.java corresponding java_org_cocos2dx_lib_cocos2dxrenderer.cpp
void Jnicall Java_org_cocos2dx_lib_cocos2dxrenderer_setispause (jnienv* env, Jobject thiz, Jboolean ispause) { Ccdirector::shareddirector ()setandroidpause (ispause); }
3. Add setandroidpause in ccdirector. cpp to mark whether it has been paused
// Set pause State void Ccdirector::setandroidpause (bool ispause) { = ispause;} // Get Pause Status BOOL Ccdirector::getandroidpause () { return m_bandroidpaused;}
4. Add a 1 step method to OnPause in Cocos2dxactivity.java under Org.cocos2dx.lib
@Override protected void OnPause () { cocos2dxrenderer.setispause (true); Super . OnPause (); Cocos2dxhelper.onpause (); This . Mglsurfaceview.onpause (); }
5. Add a line of code in the Volatiletexture::reloadalltextures () method of CCTextureCache.cpp to resume the paused state
void volatiletexture::reloadalltextures () { true; Cclog ("reload all texture"); ... ... // Intermediate content omitted here false ; // last row pause set to False Ccdirector::shareddirector ()->setandroidpause (false);}
6. When playing the music, it's time to decide if it's paused. simpleaudioengine. cpp
int Simpleaudioengine::p layeffect (constcharbool bloop) { if( Ccdirector::shareddirector (),getandroidpause ()) return0; std::string fullPath = getfullpathwithoutassetsprefix (pszfilepath); return Playeffectjni (Fullpath.c_str (), bloop);}
Android device COCOS2DX Bone Animation registration event play sound, back to the background and return to the black screen issue