lock the mouse

Started by meese72, Wed 29/06/2011 22:25:54

Previous topic - Next topic

meese72

How can one lock the mouse before a button animation & once that button animation is finished, just unlock it.
Lock, as in, the mouse  cursor is still visible but the user can't move it from its current position until it is unlocked again.

Any ideas??

Khris

You could use mouse.SetBounds.

On a side note, it can be very irritating for the player to have the mouse locked, especially if they have to sit through some eye-candy the designer wants to show for the twentieth time. I don't know what exactly you're using this for, just sayin'.

monkey0506

Just to echo what Khris said, and perhaps take it a bit further, it would be even more frustrating if the user was playing the game in a window. There are conceivable cases where you might want to lock the mouse to a certain position, say, to track its movement for certain scenarios, but the generic rule of thumb is that you shouldn't do it, at least not unless the player has control over the lock.

meese72

oOoooh....but even if it's for the teeniest tinniest time? The button animation only lasts for, like, a second, lol!

Khris

If it's for that short a time, why lock it?

BlueAngel

I could be totally wrong here but if you just want to block the player while the animation plays, can’t you put a blocking in the script for the animation?

monkey0506

#6
That actually sounds like a better alternative, though the built-in Button.Animate function (unlike Character.Animate) does not have a BlockingStyle parameter. You could make your own though:

Code: ags
// Script.ash

import void Animate2(this Button*, int view, int loop, int delay, RepeatStyle=eRepeat, BlockingStyle=eNoBlock);

// Script.asc

void Animate2(this Button*, int view, int loop, int delay, RepeatStyle repeat, BlockingStyle block)
{
  this.Animate(view, loop, delay, repeat);
  if (block == eNoBlock) return;
  int graphic = this.Graphic;
  int normal = this.NormalGraphic;
  int frame = 0;
  ViewFrame *vframe = Game.GetViewFrame(view, loop, frame);
  int frameCount = Game.GetFrameCountForLoop(view, loop);
  int counter = 0;
  while ((graphic == vframe.Graphic) && (this.NormalGraphic == normal)) // in lieu of Button.Animating
  {
    Wait(1);
    counter++;
    if (counter == delay)
    {
      frame++;
      if (frame >= frameCount) frame = 0;
      vframe = Game.GetViewFrame(view, loop, frame);
      counter = 0;
    }
    graphic = this.Graphic;
  }
}

// usage
btnButton.Animate2(VBUTTON, 0, 5, eNoRepeat, eBlock);


Seeing as I don't have access to AGS at the moment (*gasp!*), this is untested (*double gasp!*), but I think it should work as expected. The manual doesn't specify what Button.Animate uses as the default for RepeatStyle, so I might have reversed that, but again, I can't test it right now.

meese72

This way makes more sense, and I like it! I wanted to thank you all soo much for helping me!!!

monkey0506

Seeing as I never got around to actually testing this, :P does the code actually work for you? If it's not then just let me know and I'll try and debug it. Otherwise I'll assume it works fine, and rejoice in my own brilliance. :D

SMF spam blocked by CleanTalk