Hello Guest

Author Topic: tk2dSprite.Count Holds 3 Where it Should Hold 2  (Read 6476 times)

AGP

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
tk2dSprite.Count Holds 3 Where it Should Hold 2
« on: April 18, 2012, 10:12:47 pm »
I have a two-frame collection whose Count variable is storing 3. What gives? Would looping with Count-1 make sense?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.Count Holds 3 Where it Should Hold 2
« Reply #1 on: April 18, 2012, 10:14:41 pm »
Not sure. Which accessor are you using specifically?

If you're talking about the SpriteCollectionData.Count property, then this is actually possible. The sprites are stored by ID to avoid any name resolving at any stage. The editor handles deleting of sparse values by nulling out the data - i.e. the slot still exists. Newly created sprites will then take over this empty space later. For the most part you don't have to care about this, or even be aware that this even happened.

The order of sprites / frames aren't guaranteed to match any particular order. If you'd like an ordered list, the simplest method to do this is to create a SpriteAnimation, create  a clip, and add frames in the order you'd like them to appear in, and get the IDs out of this list at runtime.
« Last Edit: April 18, 2012, 10:19:53 pm by unikron »

AGP

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: tk2dSprite.Count Holds 3 Where it Should Hold 2
« Reply #2 on: April 18, 2012, 10:17:44 pm »
I don't understand your question. Where me is an instance of tk2dSprite, the line print(me.collection.Count) prints 3 where it should print 2.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSprite.Count Holds 3 Where it Should Hold 2
« Reply #3 on: April 18, 2012, 10:20:49 pm »
Yes, its the same thing I was talking about then - check post above.