Hello Guest

Author Topic: Trying to use arrays to change sprites  (Read 5040 times)

MrAdventure

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Trying to use arrays to change sprites
« on: July 13, 2016, 09:14:31 pm »
Hello,

How does one make an array of sprites and be able to assign the different sprites in editor?

Here's what I've got, which gives me an array of Tk 2d Sprite in editor.

   public tk2dSprite[] hitSprites;

   // Use this for initialization
   void Start () {

      hitSprites = GetComponentsInChildren<tk2dSprite> ();
      
When trying to assign the sprites, the pop up dialog has none available.

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Trying to use arrays to change sprites
« Reply #1 on: July 13, 2016, 10:57:43 pm »
I'm not sure waht you're trying to do here - is it an editor that displays all these sprites in one inspector?

MrAdventure

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Trying to use arrays to change sprites
« Reply #2 on: July 14, 2016, 12:51:30 am »
This picture may explain better.

.... Oops, no way to insert it.

Ok, so I'm trying to use an array to iterate through sprites. I want to apply the specific sprites within the editor.

In the array within the editor, the elements are specifically for Tk 2d Sprite. It is drag in to fill, or click the circle to choose from all of that type. When clicking, the dialog that pops up has no available Tk 2d Sprites, even though I have lots made.

They are in collections, of course. So how would I go about being able to apply specific tk2d sprites to fields within the editor?

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Trying to use arrays to change sprites
« Reply #3 on: July 26, 2016, 11:55:44 pm »
You'll need to write your own inspector. The object inspector will not pick up a tk2d sprite reference as it is an object + int reference, not just an object. Refer to the sprite editor class for how to do this - the speciifc line to start looking is this:
Code: [Select]
tk2dSpriteGuiUtility.SpriteSelector( targetSprites[0].Collection, targetSprites[0].spriteId, spriteChangedCallbackInstance, null );

MrAdventure

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Trying to use arrays to change sprites
« Reply #4 on: August 10, 2016, 04:42:01 pm »
So there isn't a built in way to iterate through tk2D sprites in code?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Trying to use arrays to change sprites
« Reply #5 on: August 20, 2016, 11:51:49 am »
You can iterate through them using foreach etc, just need to build the inspector yourself in OnInspectorGUI.