Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: meese72 on Wed 29/06/2011 22:25:54

Title: lock the mouse
Post by: meese72 on Wed 29/06/2011 22:25:54
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??
Title: Re: lock the mouse
Post by: Khris on Wed 29/06/2011 23:07:24
You could use mouse.SetBounds (http://www.adventuregamestudio.co.uk/manual/Mouse.SetBounds.htm).

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'.
Title: Re: lock the mouse
Post by: monkey0506 on Thu 30/06/2011 00:10:39
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.
Title: Re: lock the mouse
Post by: meese72 on Thu 30/06/2011 20:14:53
oOoooh....but even if it's for the teeniest tinniest time? The button animation only lasts for, like, a second, lol!
Title: Re: lock the mouse
Post by: Khris on Thu 30/06/2011 20:20:14
If it's for that short a time, why lock it?
Title: Re: lock the mouse
Post by: BlueAngel on Fri 01/07/2011 08:44:59
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?
Title: Re: lock the mouse
Post by: monkey0506 on Fri 01/07/2011 09:51:09
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:

// 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.
Title: Re: lock the mouse
Post by: meese72 on Wed 06/07/2011 18:24:25
This way makes more sense, and I like it! I wanted to thank you all soo much for helping me!!!
Title: Re: lock the mouse
Post by: monkey0506 on Wed 06/07/2011 19:02:05
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