Author Topic: Texture Atlas help  (Read 1656 times)

shrikky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Texture Atlas help
« on: February 06, 2014, 06:24:55 AM »
Hey, I am new to NGUI / Texture atlas .

I've created a texture atlas using the tutorial vids, but I don't know how to access a particular sprite from the Atlas using script. Can someone help me with this?
Example : I have an atlas named _Xatlas with 10 sprites in it. If I want to draw the sprite named "RED" if i press A, how do i do it using script?


Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Atlas help
« Reply #1 on: February 06, 2014, 09:14:04 PM »
  1. UISprite sprite = GetComponent<UISprite>();
  2. sprite.spriteName = "RED";

shrikky

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Texture Atlas help
« Reply #2 on: February 07, 2014, 12:00:40 AM »
Thanks a lot Aren, I was literally waiting for your reply and now I am able to swap images on inputs from the same atlas  :)

Is there any tutorial which covers the scripting part using NGUI? I can see a scripting reference on NGUI but I feel that it would be easier for beginners to see an example code along with it like how it is in Unity Scripting reference. Also do let me know if you have explained with scripting in any of your youtube videos.

It would be great if you can give me some input for sprite animation as well.
« Last Edit: February 07, 2014, 12:27:29 AM by shrikky »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Texture Atlas help
« Reply #3 on: February 08, 2014, 02:05:04 PM »
For a very basic example of sprite animation via code, look at UISpriteAnimation component. It has some pretty simple code inside that you are welcome to make a copy of and modify to suit your needs.