[SOLVED] Animate Cursor Once on Every Click, then Back to Normal Cursor View?

Started by The Great Underground Empire, Mon 30/03/2020 03:16:10

Previous topic - Next topic

The Great Underground Empire

I've set my cursor to Interact mode, and made it look like a hammer.

Every time I click on any character, I want the hammer to swing once, then go back to not animating.

I'm afraid I can't figure it out from the menu and a few experiments...can anyone please help?

Thanks!

Slasher

Is this for just one character?

Do you have a swing animation set up in Views?


Khris

AGS doesn't support this, at least not exactly as required; you have to implement it yourself using script commands.
One basic way is to start some kind of timer, then simply change the cursor graphic of eModeInteract as required to create the animation.
You can also use  mouse.ChangeModeView(eModeInteract, VIEW);  to start the animation based on a view (and its first loop), then call the same command again passing -1 when a suitable timer expires.

Code: ags
  // inside global on_mouse_click / eMouseLeft block
  if (mouse.Mode == eModeInteract && GetLocationType(mouse.x, mouse.y) == eLocationCharacter) {
    mouse.ChangeModeView(eModeInteract, VIEW);
    SetTimer(1, 40); // animation takes one second at 40 FPS
  }


And
Code: ags
  // inside repeatedly_execute
  if (IsTimerExpired(1)) mouse.ChangeModeView(eModeInteract, -1);

The Great Underground Empire

Nice, thanks for the help!  I'll try to implement it today.

It's a free floating hammer, the game is first person. I was thinking timers would be involved somehow but I've never animated a cursor before. :) I'll keep you posted, thanks again!

The Great Underground Empire

Ah, got it!

I had to fiddle with the timing a bit...the hammer swinging animation is only five frames long.

For some reason it kept animating like the delay was stuck on 5, even though the view said all frames were at delay 0.

I had to change the frame delays to -4, then SetTimer to 10, and that seems to have timed out perfectly at exactly one animation cycle.


Also had to use a variable to stop from clicking too many times while over the character, which could mess up the animation timing, stop it on middle frames, etc.  It toggles variable HammerSwing between 0 - timer expired, allow animation to run on click - and 1 - don't allow click until timer expires.

Code: ags

function repeatedly_execute() 
{
// Code for returning hammer cursor to normal after swing animation timer expires
if (IsTimerExpired(14)){
  mouse.ChangeModeView(eModeInteract, -1);
  HammerSwing = 0;
  }
}


Code: ags

function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeft) 
  {
    Room.ProcessClick(mouse.x, mouse.y, mouse.Mode);
    
    // Code for animating hammer swing
    if (HammerSwing == 0) {
      if (mouse.Mode == eModeInteract && GetLocationType(mouse.x, mouse.y) == eLocationCharacter) {
      mouse.ChangeModeView(eModeInteract, 11);
      SetTimer(14, 10); // animation takes one second at 40 FPS
      HammerSwing = 1;
      }
    }
  }
}



Thanks a bunch for your help!  :-D


SMF spam blocked by CleanTalk