Hello Guest

Author Topic: Issue changing sprite collections at runtime  (Read 5352 times)

aeiche

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Issue changing sprite collections at runtime
« on: September 22, 2013, 04:58:26 pm »
I'm currently switching the player between a set of high-res avatars, each of which is contained in a different collection. I have 6 separate avatars. I get through 5 out of 6 switches just fine, but the 6th just shows up as the no sprite found texture. Unless I highlight it in the editor, at which point the sprite pops in with the correct character. The builds never show the 6th avatar.

The code looks something like this:
Code: [Select]
...
public tk2dSpriteCollectionData[] avatars;
...

public void ChangeCharacter(int i){
        character = i;
       
        playerSprite.SetSprite(avatars[i-1], 0);
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue changing sprite collections at runtime
« Reply #1 on: September 23, 2013, 11:17:57 am »
Debug.Log(avatars[i-1]) - is any of them null? Secondly you should probably SetSprite(a, "name") rather than using an index - index 0 might not be the same thing on all the sprite collections...

aeiche

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Issue changing sprite collections at runtime
« Reply #2 on: September 25, 2013, 05:45:28 pm »
None of them should be null. The array is set in the editor with the prefabs.

I can switch them to use the name, but the collections only contain 1 sprite. It does appear if I select it in the editor while its running. It pops-in.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Issue changing sprite collections at runtime
« Reply #3 on: September 25, 2013, 10:25:10 pm »
Clicking on something in the editor usually "fixes up" invalid data. Its not a good measure of invalid data. Take a look at the sprite collection data object - check spriteDefinitions, etc. If you step through the code in the debugger you should find the issue straight away. If you're still stuck, send a repro case to support @ unikronsoftware.com and I'll be happy to investigate it for you.