How to load resources in loading scene between scenes

I want to load resources in loading scene between scenes. I read they suggest preLoad but I have no idea to use it. Can you explain for me how it works?

Can you give me some detail example? Thanks

Hello!

For what I know, you can preload two different kind of assets: CCObjects and Sounds.

For sounds, assuming you are using SimpleAudioEngine, you should use

    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("myMusic.wav");
    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("myEffect.wav");

This will store the effects somewhere so they will be ready to play when you call playBackgroundMusic or playEffect.

For CCObjects, the process is similar. For example, if you are using spritesheets you can prealod them using

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mySpriteSheet.plist");

Baiscally, if a structure has a Cache (SpiteFrame, Textures, Shader, Actions, etc) you can add an object to that cache. More examples:

    CCShaderCache::sharedShaderCache()->addProgram(shaderProgram, "myShaderProgram");
    CCTextureCache::sharedTextureCache()->addImage("myImage");
    CCAnimationCache::sharedAnimationCache()->addAnimation(myAnimation, "myAnimation");

This way you can add “prealod” almost everything and access it trough the same Cache instance or directly.
For example, once you have loaded sprite frame using a .plist, you can create a CCSprite using:

CCSprite *sprite = CCSprite:createWithSpriteFrameName("frameName.png");

Hope this helps :slight_smile:

Let me know if you have questions

Hi.
You mentioned an approach for sprite sheet.If we have sprites which are not in sprite sheet, for example 50 separated sprites, how should we preload them?

Thanks

There are many ways I could think of, but probably I would use something like this:

Director::getInstance()->getTextureCache()->addImage(spriteFileName);

Then you could init the sprite with this constructor for Sprite

Sprite::createWithTexture(cocos2d::Texture2D *texture);

Hope this helps : )