Hello Guest

Author Topic: Possible Sprite ID Bug  (Read 4706 times)

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Possible Sprite ID Bug
« on: March 12, 2014, 11:04:16 pm »
I have a sprite collection of thumbnail images. I then have 3 different sprite collections that together contain those same thumbnails, but as full size images.

When you select a thumbnail we need to get the same full size version. So I do this:
Quote
foreach (tk2dSpriteCollectionData data in currentTheme.SpriteCollections)
      {
         for (int x = 0; x < data.Count; x++)
         {
            string sName = data.spriteDefinitions[ x ].name;
            
            
            if (sName == spriteName)
            { //etc, etc

What we do is cycle through the sprite collections for that "group" of sprites and if we find the same named sprite lets do something with it.

The problem I'm having is on the sprites that have the ID of 0. What happens is "hat_sprite1" in collection 1 has an ID of 0, and instead of showing the hat sprite, it shows the sprite of collection 2 with ID 0.

I cannot figure out any way around this. I'm not even using IDs - just doing sprite.name comparisons.

Any ideas on how to get around this? Notice in the attached image that the sprite collection at the right is showing the proper hat image - but the one that actually shows in the viewport is a shirt.


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possible Sprite ID Bug
« Reply #1 on: March 12, 2014, 11:13:17 pm »
Its like its not updated the mesh / material. I can't see why. Can you create a simple repro case for this? That will make this a whole lot easier to track down. I am not aware of any bug like this.

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Possible Sprite ID Bug
« Reply #2 on: March 12, 2014, 11:23:11 pm »
So here is this specific instance of steps:

  • Create 2 sprite collections (in my case the first sprite collection generated 2 data files for some reason)
  • A manager object in the scene has a serializable field array of tk2dSpriteCollectionData - make its size 3 and then drag the sprite collection data files into the slots
  • Cycle through the collection data objects and do a .name comparison for the name of the sprite in the first collection that has ID of 0 (so if the sprite name "sprite_a" has a sprite ID of 0 - that is the sprite you want to use
  • do sprite.Collection = theCurrentCollectionThatTheSpriteWasIn
  • do sprite.SetSprite(theStringNameWeCompared)
  • In my case the instantiated sprite shows ID 0 of the 2nd sprite collection

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Possible Sprite ID Bug
« Reply #3 on: March 12, 2014, 11:45:55 pm »
This may well be a bug. I'll investigate.
Have you tried SetSprite(newCollection, newSprite) ?

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Possible Sprite ID Bug
« Reply #4 on: March 12, 2014, 11:59:17 pm »
That fixed it!!! Looks like its probably a bug!