How to access Atlas property of Sprite listed in Editor

How to access Atlas property of Sprite listed in Editor

Hello. I can not find out how to access Atlas property which is listed in Editor for Sprite component.

I know how to load atlas using cc.loader.loadRes, but it looks i should not load is twice if it already was loaded.

Thank you in advance.

i don’t think it’s possible (or maybe there’s some hidden API?). the only thing you can do is access the spriteFrame and set it:

this.getComponent(cc.Sprite).spriteFrame = someOtherSpriteFrame;

maybe it would be possible to cc.SpriteFrame.getTexture() and compare Texture2D#name or url to existing ones to somehow reverse lookup.

is it possible to find list of atlases loaded by editor? I’m ok to do reverse lookup but I couldn’t find atlas?

if you’re loading your SpriteAtlases using Loader#loadRes or similar, then, obviously, you can :smiley:

if not, there might be a possiblity to use Loader#getDependsRecursively. Instead of sending the url of a prefab, as in the example, you could sent the uuid of the current scene: cc.director.getScene().uuid

1 Like

I’ve solved my problem in different way though, I tried your suggestion also.

It only returns current scene uuid:

how did you end up doing it?

I’ve made a texture packer which puts image rgb and alpha channels side by side in a jpeg.

I needed to find correct alpha frame for each spriteFrame with name.
Finally I couldn’t get the atlas.
So I defined a naming convention for my atlas frames.
Frame names like: “spaceship_rgb” “spaceship_a”
I check the name of spriteFrame onLoad, if it ends with “_rgb” I apply a shader to offset texture coordinates to get alpha values corresponding.

I still don’t know where is the atlas data but I’ve managed to get alpha from correct coordinates :slight_smile: