Changing the img on a button.

Started by Icey, Tue 11/01/2011 04:11:54

Previous topic - Next topic

Icey

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...
Code: ags

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
}


Ryan Timothy B

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.

Icey

I see, I read the the manual but I was still lost. I will check that out.

monkey0506

Also, instead of having to comment each time you use a Button to keep track of which one it is:

Code: ags
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?

Code: ags
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.

SMF spam blocked by CleanTalk