Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: holmiboii on October 16, 2014, 01:24:54 PM

Title: Displaying Int value with Sprites?
Post by: holmiboii on October 16, 2014, 01:24:54 PM
Hello People! I was just wondering is there any way to convert my "Health value" that is stored in a Int could be displayed in runtime as Sprites?
The Sprites are in a NGui atlas so.. thought?
Title: Re: Displaying Int value with Sprites?
Post by: badawe on October 16, 2014, 03:27:14 PM
Hello People! I was just wondering is there any way to convert my "Health value" that is stored in a Int could be displayed in runtime as Sprites?
The Sprites are in a NGui atlas so.. thought?
I'm not sure of what you're asking, but the answer is YES YOU CAN!

Just keep a reference of this sprite, and change the sprite as your health value.

Like:
  1. if(health < 10)
  2. {
  3.      targetSprite.spriteName = "LowHealth";
  4. }
Title: Re: Displaying Int value with Sprites?
Post by: holmiboii on October 16, 2014, 05:29:23 PM
Thanks for the quick reply, I guess that I wasn't clear enough..
The thing is the "Health" is in two digits. So I'm using numbers 0 - 9.
Every player got 20 health to start off with, they are divided, so the number 2 and 0 are stored in the same int, but not the sprites.
Etc:
|2| |0|
|1| |9|
|0| |9|
Title: Re: Displaying Int value with Sprites?
Post by: ArenMook on October 17, 2014, 04:59:20 AM
  1. int health = 20;
  2.  
  3. string strHealth = health.ToString();
  4.  
  5. leftSprite.spriteName = strHealth.Length < 2 ? "0" : strHealth[0].ToString();
  6. rightSprite.spriteName = strHealth.Length < 2 ? strHealth[0].ToString() : strHealth[1].ToString();