Changing GUI Button sprites

Started by idiotbox, Wed 26/10/2005 20:21:00

Previous topic - Next topic

idiotbox

Okay, I have a healthbar in my GUI. Now I've looked in the manual but can't find what I want. Is there a way to change the sprite on the button when my health int decreases?

Something like

if (health==90){
Ã,  Ã,  //change image//
}

etc.
Ã,  Ã, 

Ashen

#1
Button.NormalGraphic property should be what you're after. (And possibly MouseOverGraphic and  PushedGraphic too.)

So:
Code: ags

if (health == 90) {
  btnHealth.NormalGraphic = 54; // where 54 is the spriteslot of the new image
}

//etc


However, depending on what exactly is on the graphic there may be another way to do it. For example, if the button is a bar that you want to shrink or grow depending on your health, you could use the ClipImage property, and just change the button's size accordingly.
I know what you're thinking ... Don't think that.

idiotbox

Thanks a lot. I was just confused earlier.

RickJ

You may want to lookup Button.ClipImage in the manual also.   Set this property to true and then you can just resize the button to implement a bar graph.

idiotbox

It is now saying btnHealth is an undefined token and
I even put the int on the top of global script and it says it's already been defined. Am I doing something wrong?

Ashen

No, I did - kind of. I should've mentioned that btnHealth needs to be replaced with the script name of the button you want to change the graphic of. You can check (or set, if needed) the script name on the GUI editor window. Sorry about that.
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk