Getting GuiButton to Appear when MouseClicks then Animate on MouseHover (SOLVED)

Started by Vera, Mon 20/07/2009 08:52:02

Previous topic - Next topic

Vera

I need a little help getting part of this script to work. Here's some info that may or may not be more than needed... if so just skip to The Problem toward the bottom of my post.

The GUI:
I have a particular GUI that only shows up in one room, since it's a New/Load/Delete Game type of thing. So, the GUI automatically appears upon entering that room, and doesn't appear anywhere else.

The Buttons:
Not all the buttons are initially visible.
At first, all you see is 3 buttons that represent the 3 different save slots (whose graphics vary depending on if the slot is used or empty), a DELETE button (for deleting previously saved files), a QUIT button, and finally a button at the top (that doesn't actually do anything, but it's image graphic tells the player what to do).

The buttons not initially visible are 3 buttons that determine which save slot to delete, an OK button (which confirms the deletion), and a different QUIT button (which cancels the deletion & takes you back to the main selections).

What I'm trying to achieve:
When you click on the DELETE button, the 3 "New/Load" buttons + the "Delete" button + the "Quit" button all go invisible. At the same time, the "does nothing" button at the top gets its normal graphic changed and is repositioned. Also, the 3 "Delete this Slot" buttons become visible.

Now the player can click one of the 3 "Delete this Slot" buttons. Then they go invisible, the top "does nothing" button changes its normal graphic again, and the "OK" + "Quit/Cancel" buttons appear.

Then the player can click OK to delete that file, or QUIT to return to the original selections (New/Loadx3 + Erase + Quit).

All the buttons (except the "does nothing" button at the top) are supposed to animate on mouse-over.

------------------------------------------

This is the code I have in my Global Script concerning this GUI's "Erase" button:

Code: ags
// STARTUP GUI - Erase File (Erase Button)
function btnEraseSave_OnClick(GUIControl *control, MouseButton button)
{
  btnSaveSlot1.Visible = false;
  btnSaveSlot2.Visible = false;
  btnSaveSlot3.Visible = false;
  btnEraseSave.Visible = false;
  btnCancelSave.Visible = false;
  btnChooseFile.NormalGraphic = 81;
  btnChooseFile.SetPosition(50, 0);
}


This is the code I have in the Room Script:

At the top of the room's script:
Code: ags
bool File1Animating;
bool File2Animating;
bool File3Animating;


In the room's RepExec function:
Code: ags
  // Show FILE selection if ERASE is clicked on
  if (btnChooseFile.NormalGraphic == 81) {
    btnFile1.Visible = true;
    btnFile2.Visible = true;
    btnFile3.Visible = true;
  }
  else {
      btnFile1.Visible = false;
      btnFile2.Visible = false;
      btnFile3.Visible = false;
  }
  // File 1 ANIMATION
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == btnFile1) {
    if(File1Animating == false) {
      btnFile1.Animate(8, 0, 5, eRepeat);
      File1Animating = true;
    }
    else {
      btnFile1.NormalGraphic = 85;
      File1Animating = false;
    }
  }
  // File 2 ANIMATION
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == btnFile2) {
    if(File2Animating == false) {
      btnFile2.Animate(12, 0, 5, eRepeat);
      File2Animating = true;
    }
    else {
      btnFile2.NormalGraphic = 130;
      File2Animating = false;
    }
  }
  // File 3 ANIMATION
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == btnFile3) {
    if(File3Animating == false) {
      btnFile3.Animate(13, 0, 5, eRepeat);
      File3Animating = true;
    }
    else {
      btnFile3.NormalGraphic = 141;
      File3Animating = false;
    }
  }


That's supposed to check if the "does nothing" button has a certain graphic (a "Delete which file?" image) then the 3 "Delete this file" buttons are shown (File 1, File 2, File 3).

------------------------------------------

The Problem
The 3 buttons that appear to allow the player to select which slots to delete DO appear as they should, BUT they won't animate correctly on mouse-over. They flicker. I think I've read somewhere about people experiencing this animation flicker, but I'm not sure how to fix my script specifically. Do I need to move some code around? Is it because some of the GUI's script is only in the room script, and some is in the global script? Because I wasn't really sure what should go where, since this GUI will only be appearing in this one room. Or perhaps it has something to do with the RepExec?

Any suggestions would be appreciated. Thank you!

Khris

I didn't realize what the problem was until I was in the middle of typing the code into a default game:
The else blocks needs to correspond to the first if:
Code: ags
  // File 1 ANIMATION
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == btnFile1) {
    if(File1Animating == false) {
      btnFile1.Animate(8, 0, 5, eRepeat);
      File1Animating = true;
    }
  } // <- close here
  else {   // stop animation if mouse isn't over the button
    btnFile1.NormalGraphic = 85;
    File1Animating = false;
  }


With your code, the animation was started and stopped every other frame, thus the flickering.

Vera

Ah, of course! Thank you again, it works now. I guess I need to pay more attention to placement when I come across a problem.

I'm learning a lot as I go along  :)

SMF spam blocked by CleanTalk