2D Toolkit Forum

2D Toolkit => Support => Topic started by: fxfx on June 17, 2015, 04:43:48 pm

Title: Spritedefinitions returning zero
Post by: fxfx on June 17, 2015, 04:43:48 pm
I am trying to get a list of all sprite names in a Sprite Collection during runtime. I put the data file in Resources folder, and then try to get all the names by code:

tk2dSpriteCollectionData atlas = Resources.Load("atlas", typeof(tk2dSpriteCollectionData)) as tk2dSpriteCollectionData;

foreach (tk2dSpriteDefinition spritedefinition in atlas.spriteDefinitions) {
           Debug.Log(spritedefinition.name);
}

The weird thing is that it works for one Sprite Collection, and not the other. The other Sprite Collection is showing 0 spriteDefinitions count.
I checked and the only difference between the two Sprite Collection is that the one returning 0 has 3 platforms (@1x, @2x, @4x)

Any help will be appreciated. Thanks!
Title: Re: Spritedefinitions returning zero
Post by: unikronsoftware on June 17, 2015, 06:17:50 pm
If it has platforms, you should use atlas.inst.spriteDefinitions. That will return the loaded platform collection. In fact you can safely do that all the time.
Title: Re: Spritedefinitions returning zero
Post by: fxfx on June 17, 2015, 07:25:45 pm
It works. Thanks!  :)