Android device COCOS2DX Bone Animation registration event play sound, back to the background and return to the black screen issue

Source: Internet
Author: User

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 under Org.cocos2dx.lib

 Public Static native void Setispause (boolean ispause);

2. Add the corresponding method in the 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 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.