Hello Guest

Author Topic: Getting SpriteID into XML  (Read 3943 times)

Phuzz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Getting SpriteID into XML
« on: January 08, 2015, 10:38:16 am »
Hello,

I recently added XML level loading into my project from this tutorial [http://www.teambrookvale.com/tutorial-xml-level-unity/]

----------------------------

I am not able to get the DeserializedLevelsSaver Class to read the tk2dsprite component in my prefab, so whenever I load a level all transformation is correct and it loads properly, but the sprite is not set because the component is not being saved to XML.

I am Using Playmaker with 2dToolkit, so I use Playmaker actions for everything related to 2dToolkit, but im very new to scripting, that's where the problem lies even though I know its easy.

I am getting a bit confused about getting the sprite ID component into the XML, I know it goes here,

levelXml.items.prefab =    item.name;
levelXml.items.x =       toStringNullIfZero (item.transform.position.x);
levelXml.items.y =       toStringNullIfZero (item.transform.position.y);
levelXml.items.rot =    toStringNullIfZero (item.localRotation.eulerAngles.x);
levelXml.items.scale_x = toStringNullIfOne  (item.localScale.x);
levelXml.items.scale_y = toStringNullIfOne  (item.localScale.y);
levelXml.items.id = ToString ();    <--------------------------------------------------------------- (The missing Part)

Please if someone can spare two minutes of their time and provide me with the missing part "Get sprite ID of current prefab", I am able to manager the other classes, but this is the only pickle.  :-\

Thank you,

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Getting SpriteID into XML
« Reply #1 on: January 09, 2015, 06:05:24 pm »
item.GetComponent<tk2dBaseSprite>().spriteId will get you the sprite id.

Phuzz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Getting SpriteID into XML
« Reply #2 on: January 10, 2015, 06:06:45 pm »
Great, works very well thank you :)  8)