Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Icey on Tue 11/01/2011 04:11:54

Title: Changing the img on a button.
Post by: Icey on Tue 11/01/2011 04:11:54
Can someone please tell me that there is a code that will let you change a gui button img. I want the button graphic to change when I click it

I got this...

function Button12_OnClick(GUIControl *control, MouseButton button)
{
Dave.SetAsPlayer();
Button12.Graphic = 87;//dave
Button14.Graphic = 90;//tifa
Button15.Graphic = 88;//muffy
button13.Graphic = 92;//chris
}

Title: Re: Changing the img on a button.
Post by: Ryan Timothy B on Tue 11/01/2011 04:18:59
As the manual states:
Quotereadonly int Button.Graphic;
Gets the current image on a GUI button. If a value less than 1 is returned, then no image is currently displayed on the button.
That means Button.Graphic is readonly.

Under that it even clearly describes this by saying:
QuoteThis property is read-only; in order to set the image, you must use one of the NormalGraphic [..]
So to change the graphic of a button, you'll need to use Button.NormalGraphic

Not trying to be harsh. Just showing you how useful the manual can be if you actually read it.
Good luck.
Title: Re: Changing the img on a button.
Post by: Icey on Tue 11/01/2011 04:30:11
I see, I read the the manual but I was still lost. I will check that out.
Title: Re: Changing the img on a button.
Post by: monkey0506 on Tue 11/01/2011 14:55:10
Also, instead of having to comment each time you use a Button to keep track of which one it is:

Button12.NormalGraphic = 87;//dave
Button14.NormalGraphic = 90;//tifa
Button15.NormalGraphic = 88;//muffy
Button13.NormalGraphic = 92;//chris


Why not just change their script names to something more descriptive?

btnDave.NormalGraphic = 87;
btnTifa.NormalGraphic = 90;
btnMuffy.NormalGraphic = 88;
btnChris.NormalGraphic = 92;


This is done via the Properties pane for each of the Buttons, in the GUI editor.