Animate button when mouse is no longer on it **SOLVED**

Started by Knox, Thu 23/06/2011 23:27:08

Previous topic - Next topic

Knox

Hi,

I based this script on what Khris suggested in this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=43755.0

Code: ags

function repeatedly_execute_always() 
{
  GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (gc == bTest) 
  {
    if (!bRollOverBtnAnim) 
    {
      bTest.Animate(VCRL_ROLLOVERS, 0, 1, eOnce);
      bRollOverBtnAnim = true;
    }
  }
  else if (gc != bTest)
  {
    bTest.Animate(VCRL_ROLLOVERS, 1, 1, eOnce);  // this animation doesnt play at all when the mouse leaves the button
    if (bTest.NormalGraphic != 2752) bTest.NormalGraphic = 2752;
    bRollOverBtnAnim = false; 
  }  
}


What Im trying to do is when the mouse is over a certain button, it plays an animation once. As soon as it leaves the button (no longer over it), it plays another animation, then returns to its normal graphic.

The 1st animation plays OK, but when my mouse is no longer on the button, that 2nd animation doesnt play at all.

What did I do wrong?
--All that is necessary for evil to triumph is for good men to do nothing.

Knox

Ok, I solved it! I was missing a 2nd bool. Here is the code for those who want to do something similar:
Code: ags

bool bRolledOver = false;
function repeatedly_execute_always() 
{
  GUIControl*gc = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  if (gc == bTest) 
  {
    if (!bRollOverBtnAnim) 
    {
      bTest.Animate(VCRL_ROLLOVERS, 0, 1, eOnce);
      bRollOverBtnAnim = true;
      bRolledOver = true;
    }
  }
  else if (gc != bTest)
  {
    if (bRolledOver)
    {
      //Display("Rolled Over...and no longer over button: play 2nd animation");
      bTest.Animate(VCRL_ROLLOVERS, 1, 1, eOnce);
      bRolledOver = false;
      bRollOverBtnAnim = false;
    }
  }  
}

--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk