Author Topic: Button graphic animation loop prevents mouse clicking  (Read 181 times)

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: Adventure Game Studio
  1. function animatemenu()
  2. {
  3.   btnMenu.NormalGraphic = 15;
  4.   Wait(7);
  5.   btnMenu.NormalGraphic = 13;
  6.   Wait(7);
  7.   btnMenu.NormalGraphic = 11;
  8.   Wait(7);
  9.   }
  10. }
  11.  
  12. function repeatedly_execute()
  13. {
  14.   //Animate Menu Button
  15. GUIControl*button=GUIControl.GetAtScreenXY(mouse.x,mouse.y);
  16. if (button==btnMenu) {
  17. animatemenu();}
  18. }

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!

Re: Button graphic animation loop prevents mouse clicking
« Reply #1 on: 10 Jun 2018, 04:32 »
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: Adventure Game Studio
  1. int tic_counter;
  2.  
  3. function animatemenu()
  4. {
  5.   tic_counter=tic_counter+1;
  6.  
  7.   if(tic_counter>21){
  8.     btnMenu.NormalGraphic = 15;
  9.     tic_counter = 0;
  10.   } else if(tic_counter>14){
  11.     btnMenu.NormalGraphic = 11;
  12.   } else if(tic_counter>7){
  13.     btnMenu.NormalGraphic = 13;
  14.   }
  15. }
  16.  
  17. function repeatedly_execute()
  18. {
  19.   //Animate Menu Button
  20.   GUIControl*button=GUIControl.GetAtScreenXY(mouse.x,mouse.y);
  21.   if (button==btnMenu) {
  22.     animatemenu();
  23.   }
  24. }
  25.  

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on a game that was nominated for an AGS Award!
Re: Button graphic animation loop prevents mouse clicking
« Reply #2 on: 10 Jun 2018, 07:58 »
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...

Re: Button graphic animation loop prevents mouse clicking
« Reply #3 on: 10 Jun 2018, 16:08 »
Hahaha I literally didn't knew this was possible, AGS really has so much stuff 8-0

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
    • Crimson Wizard worked on a game that was nominated for an AGS Award!
      Crimson Wizard worked on a game that won an AGS Award!
Re: Button graphic animation loop prevents mouse clicking
« Reply #4 on: 10 Jun 2018, 16:09 »
There is also Button.Animate() which runs animation when you want, and to stop it set Button.NormalGraphic again.
« Last Edit: 10 Jun 2018, 16:11 by Crimson Wizard »

Re: Button graphic animation loop prevents mouse clicking
« Reply #5 on: 12 Jun 2018, 15:53 »
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!