Getting current SpriteAtlas

Getting current SpriteAtlas
0
#1

Hello.

Is there any way to get the current Sprite atlas in script?
I would like to set the atlas in the editor, then animate by code.
But I don’t see any property/method to get the atlas.

I only know how to do it using cc.loader and adding a custom SpriteAtlas property like so:
atlas:{ default: null, type: cc.SpriteAtlas }

Setting the atlas in the editor, the cc.loader is not a solution.
Also, adding a custom property in the script means making two redundant assignments instead of one.
Something like
var atlas = this.getAtlas()
and then use getSpriteFrame would be great.
Any alternative is welcome.

Thank you.

0 Likes

#2

maybe you mean :
let atlas = this.node.getComponent(cc.Sprite)._atlas
but you know : _atlas is a private variable of cc.Sprite

0 Likes