Questions about SpriteAtlas

Hi forum!

I keep going with my game but I have a couple of questions about SpriteAtlas

1, What is the function of “Select in atlas” I click it and nothing happened.
Capture3

2, I have a prefab with Atlas linked on sprite component, but how can I change the frame name by code?

var player = cc.instantiate(this.player);
player.getComponent(cc.Sprite).spriteFrame.setTexture('player2');

The code above try to load player2.png by url, but I just want to change atlas frame.

3. Where are the texture atlas stored? I’m using a preload script to load my Atlases on the first scene, then when I try to find it on texture cache there are only images but not the processed atlas, I need to process it again or store it in a global variable?

thanks :slight_smile:

Hi!
If you preload your atlases manually, keeping a global ref would be a good idea, or you can always access through cc.loader.get methods
Also you need to get down some cocos namings:

  • texture is raw bitmap data, pngs as they are, heavy stuff
  • spriteFrame is a subregion of a texture, specified by it’s coordinates, lightweight
  • spriteAtlas is a set of spriteFrames that all use the same texture, lightweight

So for stuff like sequence animations you need to change spriteFrame of cc.Sprite, given that you already have them packed into a neat atlas.
Try this, assuming you have you atlas at /resources/stuff/atlas.png and /resources/stuff/atlas.json. Or .plist? I tend to use AutoAtlases not sure here:

cc.loader.loadRes('stuff/atlas', cc.SpriteAtlas);     // preloading part
//-----
var atlas = cc.loader.getRes('stuff/atlas', cc.SpriteAtlas);
var player = cc.instantiate(this.player);
player.getComponent(cc.Sprite).spriteFrame = atlas.getSpriteFrame('player2');

@persy I’m using plist, cc.loader.getRes() is was I looking for, works well, thanks

Does anyone know about “Select in atlas”? has a bug or why it is not working?