Author Topic: Displaying Int value with Sprites?  (Read 6694 times)

holmiboii

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Displaying Int value with Sprites?
« 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?

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: Displaying Int value with Sprites?
« Reply #1 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. }

holmiboii

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Displaying Int value with Sprites?
« Reply #2 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|

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Displaying Int value with Sprites?
« Reply #3 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();