Music turns off in windows [SOLVED]

I just discovered a problem that’s been in my game a while on the windows version of my app (it works fine on iOS). Apparently, the AppDelegate::applicationDidEnterBackground() and AppDelegate::applicationWillEnterForeground() methods aren’t called on the Windows version?

What my game does in those methods is pause the animation and music, and then resume them.

Well, on the Windows version, something is definitely pausing the music, but it doesn’t resume, and when I debug with breakpoints, neither of those methods is getting called.

I found a solution, made a slight change in CCGLViewImpl-desktop.cpp. I looked at the onGLFWWindowIconifyCallback and used that logic to update onGLFWWindowFocusCallback().

void GLViewImpl::onGLFWWindowFocusCallback(GLFWwindow* /*window*/, int focused)
{
    if (focused == GL_TRUE)
    {
        Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_FOCUSED, nullptr);
        Application::getInstance()->applicationWillEnterForeground();
    }
    else
    {
        Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GLViewImpl::EVENT_WINDOW_UNFOCUSED, nullptr);
        Application::getInstance()->applicationDidEnterBackground();
    }
}

works like a charm now!

1 Like