How to load multiple sprites from resource folder

I am new to Cocos creator. I wanted to load several sprites from the resources folder.

I wrote following code by looking at the example that comes with creator.
How do I load multiple sprites?
I know there is some delay in loading the resources so I can’t just call the function multiple times right?
What is the correct way of doing this?

I am also confused about following line, what does it do? Why can’t I call “_loadCallBack” directly?
var loadCallBack = this._loadCallBack.bind(this);

onLoad: function () {
    this.initReelSprite(1);
},

initReelSprite: function(spriteId)
{
    this._itemSprite = this.getComponent(cc.Sprite);
    var loadCallBack = this._loadCallBack.bind(this);
    cc.loader.loadRes("SlotSymbols/ap_sym_"+spriteId, cc.SpriteFrame, loadCallBack);
},

_loadCallBack: function (err, res) {
    if (err) {
        cc.log('Error url [' + err + ']');
        return;
    }
    this._itemSprite.spriteFrame = res;
},
1 Like

Any news about this. I want also load some sprites with cc.loader.loadRes in a for loop.

for( let i = 0; i < sprites.length; ++i )
{
  cc.loader.loadRes( 'atlas/race', cc.SpriteAtlas, function (err, atlas) {
    node = new cc.Node( 'Sprite ' + i );
    frame = atlas.getSpriteFrame( sprites[ i ].name );
    ...
  });
}

This works, but the node order is different to my sprites array order.

Thank

Mike

I solved my order problem with a node.zIndex

You could use cc.loader.loadResAll for multiple resource loading. After loading you could loop through the data to access elements.

Hi onur,

I will try it, thank you very much.

Mike