Button graphic animation loop prevents mouse clicking

Started by SmugMonster, Sun 10/06/2018 02:07:16

Previous topic - Next topic

SmugMonster

Hello ladies and gents! I have a question, but first I'll explain what results I'm after:

I want a button to loop through a series of graphics as long as the mouse is hovered over it.

My current bit of code looks like this:
Code: ags

function animatemenu()
{
  btnMenu.NormalGraphic = 15;
  Wait(7);
  btnMenu.NormalGraphic = 13;
  Wait(7);
  btnMenu.NormalGraphic = 11;
  Wait(7);
  }
}

function repeatedly_execute() 
{
  //Animate Menu Button
GUIControl*button=GUIControl.GetAtScreenXY(mouse.x,mouse.y);
if (button==btnMenu) {
animatemenu();}
}


So - this is functioning, it's looping the graphics exactly as I want. Couple problems with it, though:

It's causing the mouse cursor to vanish when hovering. It appears again very very briefly when the cycle completes. This is causing the mouse cursor to flicker in time with the cycles, with isn't very aesthetic, but isn't a huge problem...

... the main issue is that the mouse also can't click the button. Clicking doesn't do anything (worth noting that I've checked that, without this function, clicking works just fine).

I've tried adding a mouse.IsButtonDown(eMouseLeft) as a condition but that didn't work. I'm probably going about this in an inefficient manner - is there a better way of getting this result without making the mouse disappear/unable to click?

Thanks folks!

eri0o

the Wait function is blocking, which is usually something you do not want in a repeatedly_execute. Instead, account for each tick that repeatedly execute rans and use it as wait... Something like:

Code: ags

int tic_counter;

function animatemenu()
{
  tic_counter=tic_counter+1;

  if(tic_counter>21){
    btnMenu.NormalGraphic = 15;
    tic_counter = 0; 
  } else if(tic_counter>14){
    btnMenu.NormalGraphic = 11;
  } else if(tic_counter>7){
    btnMenu.NormalGraphic = 13; 
  } 
}
 
function repeatedly_execute() 
{
  //Animate Menu Button
  GUIControl*button=GUIControl.GetAtScreenXY(mouse.x,mouse.y);
  if (button==btnMenu) {
    animatemenu();
  }
}

Cassiebsg

Why are you animating a button that way?
There's a "MouseoverImage" property for buttons, just create a view with the graphics you want and then assign the view number to this property. (nod)

Or you can go the complicated route and code it like eri0o suggested, if for some reason the easy solution doesn't work for you.
There are those who believe that life here began out there...

eri0o

Hahaha I literally didn't knew this was possible, AGS really has so much stuff 8-0

Crimson Wizard

#4
There is also Button.Animate() which runs animation when you want, and to stop it set Button.NormalGraphic again.

SmugMonster

I'll try the tick counter thing if none of the other options work for me.

I'm animating it because the mouseover image is exactly that - just an image, where I want it to cycle through multiple frames. Didn't let me pick a view, only a sprite ... I'll check out the Button Animate thing and see if that does what I'm looking for. If not, I'll do the ticks instead. Thanks, guys!

SMF spam blocked by CleanTalk