This site requires JavaScript, please enable it in your browser!
Greenfoot back
-nic-
-nic- wrote ...

2012/4/9

changeing the img

-nic- -nic-

2012/4/9

#
i would like to change the png as the <objects> health lowers but in cant figure it out??? i have the health bar from danposts senario progress bar/health bar!!
SPower SPower

2012/4/9

#
You need to know the previous health, and you of course need to know the new health. If your new healt is less than the previous health, you can use the setImage() action to change the image. Between the () you put the name of your picture, which is stored in the pictures folder of your project, between "" like:
setImage("myImage.png");
-nic- -nic-

2012/4/9

#
that bit i understand but how would you find the previus health and the new health health??
SPower SPower

2012/4/9

#
Create an instance variable for your previous healt:
private int previousHealth;
If you have a method which sets the health - a parameter, add this line at the beginning of that method:
previousHealth = yourVariableWhichHoldsTheCurrentHealth;
Also add another method:
private void lookForHealthDifference()
{
if (previousHealth > yourVariableWhichHoldsTheCurrentHealth) {
       setImage("myImage.png");
}
}
Call this method from the method which sets the health - a parameter:
lookForHealthDifference();
Succes!
SPower SPower

2012/4/9

#
You have to call lookForHealthDifference() at the end of the method :)
-nic- -nic-

2012/4/9

#
would the yourVariableWhichHoldsTheCurrentHealth be a class ??
SPower SPower

2012/4/9

#
No, just an instance variable:
private int yourVariableWhichHoldsTheCurrentHealth
This must be stored in the class which shows the health, because it MUST know what to display!
SPower SPower

2012/4/9

#
Oops, forgot the ; :)
-nic- -nic-

2012/4/9

#
oh it was just value ;'(
-nic- -nic-

2012/4/9

#
private int value
SPower SPower

2012/4/9

#
that's also possible, is just said yourVariableWhichHoldsTheCurrentHealth because that would be easier to understand for you as you would read it here, but I didn't meant you must use it in your project.
-nic- -nic-

2012/4/9

#
ok im really confused im useing danpost's health bar and i cant find health value but i just had idear :D
SPower SPower

2012/4/9

#
You maybe have to redo your code of the health bar, and start off by using a variable which you convert into a health bar. That's what I do sometimes when I realize I did something wrong.
-nic- -nic-

2012/4/9

#
[Disallowed URL] [Disallowed URL] the first is the bosshealth classes value and the second is the bosses value but there different
You need to login to post a reply.