0
\$\begingroup\$

When the loading screen loads objects like music cutscenes, the idea is to preload the objects, so... what should happen next? Do I transfer the objects to the next scene? or these special objects, media objects or even just images of the sprites, do they have to be part of a Singleton? According to my logic, singleton is a simple solution, that can I use whatever was preloaded in the loading screen to take to the game. The only drawback is that I have to keep management of these objects to unload them when out of the game scene.(its just an example, but its really close to what my game is doing).

The thing is, i believe there is a more elegant solution to this problem. Anyone has any suggestions? or tell me if my method is wrong?

\$\endgroup\$
0
\$\begingroup\$

in Cocos2D, doesn't the music continue to play until you pause or stop it?

If I want to change music between CCScene I usually do something like:

_dir->Instance()->getAudioEngine()->stopBackgroundMusic();
_dir->Instance()->getAudioEngine()->stopAllEffects();

// click!
_dir->Instance()->getAudioEngine()->playEffect("click.mp3", false);

...do whatever

Edit:

I dont use the shared director. I created my own director object with everything I need as member variables.

I load my music like this:

void AppDirector::createAudioEngine()
{
    CocosDenshion::SimpleAudioEngine* ae = new CocosDenshion::SimpleAudioEngine();

    ae->preloadBackgroundMusic("Tallahassee.mp3");
    ae->preloadBackgroundMusic("bigcountry.mp3");

    ae->preloadEffect("click.mp3");
    ae->preloadEffect("tap.mp3");

    ae->setBackgroundMusicVolume(0.5f);
    ae->setEffectsVolume(0.3f);

    setAudioEngine(ae);
}

Edit 2:

I do this:

AppDirector* AppDirector::Instance()
{
    if (pinstance == 0) // is it the first call?
    {
        pinstance = new AppDirector; // create sole instance
        pinstance->initInstance(); // setup everything we need.
    }

     return pinstance; // address of sole instance
}

void AppDirector::initInstance()
{
    createFileUtils();

    createDirector();

    // set some defaults
    setIsHUDDisplayed(false);

    createTouchDispatcher();

    createAudioEngine(); // created and preloads music and sound effects.

    createOpeningScene();
}
\$\endgroup\$
  • \$\begingroup\$ how do you load that music? so you are saying that since its part of the director, I dont need to worry? But what about the other objects like sprites and animations? \$\endgroup\$ – user31088 Aug 3 '13 at 20:22
  • \$\begingroup\$ see edit above. \$\endgroup\$ – Jason Aug 3 '13 at 21:46
  • \$\begingroup\$ ahhh so the singleton is the answer. by having everything ready, I just use it when needed inside the game scene right? \$\endgroup\$ – user31088 Aug 3 '13 at 21:50
  • \$\begingroup\$ oh, indeed, yup my "AppDirector" class is a singleton, I create everything I need as member variables. I know cocos2d has the shared director concept, but I really felt like doing things this way provided me a lot of flexibility as well as ease of use. (at least for me) \$\endgroup\$ – Jason Aug 3 '13 at 21:56
  • \$\begingroup\$ yes, i understand I do have a singleton for several things, it does make the job easier. But so when you destroy the scene, I suppose you destroy the objects too right? like unload the music from the singleton since its no longer needed? \$\endgroup\$ – user31088 Aug 3 '13 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy