My game needs to update the background of a TextView in every class onCreate to show the health of the player, however at the moment the only way i can think of doing it is this
int Health = 100;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act1);
if (Health == 100){
HealthDisplay.setBackgroundResource(R.drawable.health100);
} else if (Health == 99){
HealthDisplay.setBackgroundResource(R.drawable.health99);
} else if (Health == 98){
HealthDisplay.setBackgroundResource(R.drawable.health98);
} else if (Health == 99){
HealthDisplay.setBackgroundResource(R.drawable.health98);
} else if (Health == 99){
HealthDisplay.setBackgroundResource(R.drawable.health98);
} else if (Health == 99){
HealthDisplay.setBackgroundResource(R.drawable.health98);
}
etc.
}
There has to be an easier/ faster way of doing this, especially as i need to do similar for two other stats as well.
I have thought about having a separate class handle it and have a line or two in the onCreate that tells it to run that class to update the background image then return to this one.
Alternatively perhaps something like this is possible?
int Health = 100;
HealthDisplay.setBackgroundResource(R.drawable.health(Health));
What I would suggest is having one image (for full health) and each time crop it and show a percentage of it according to your health level. For example:
and then in another thread you would call: