Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Technocrat on Wed 02/12/2009 17:41:41

Title: Making an int change with mouse movement...
Post by: Technocrat on Wed 02/12/2009 17:41:41
No idea if I'm fundamentally misunderstanding how AGS's mouse things work, and do point me in the right direction if I am, but I'm wondering if there's a means of getting an int to change with the mouse's movement. In my case for example, increasing as it moves to the right, and decreasing towards the left. I was thinking of something like using the mouse's.y position on the screen, but a) the int would never get below 0 or above 320, and b) the int would always be the y position, rather than consistently increasing with right movement, and vice versa.

Hopefully I've made myself clear enough! Merci beaucoup.
Title: Re: Making an int change with mouse movement...
Post by: DoorKnobHandle on Wed 02/12/2009 17:46:07
What you need to do is:

Every frame, get the current mouse position on the x-axis. Compare this value to the mouse position from last frame. If they differ, the mouse was moved recently, take that difference and add it to your variable and that's it. :D

This is absolutely untested code (and I haven't played with this kind of AGS coding in a while):


int old_mouse_x;
int variable;

function rep_ex ( )
{
      int mouse_x = mouse.X;

      if ( mouse_x != old_mouse_x )
      // if the mouse was moved recently
            variable += mouse_x - old_mouse_x;

      // store the current mouse position as the old one for the next frame to use
      old_mouse_x = mouse_x;
}


In this example, 'variable' will be the value you're looking for. Try displaying it on a GUI or something to check it out.

Hope this helps, let me know if there are any problems.
Title: Re: Making an int change with mouse movement...
Post by: Technocrat on Wed 02/12/2009 19:03:38
Ah, I see. For my purposes, if I use your script verbatim, it's making an array go out of bounds, so now I'm adapting it to my purposes as well based on that. Many thanks!
Title: Re: Making an int change with mouse movement...
Post by: Calin Leafshade on Wed 02/12/2009 19:12:48
sorry i dont quite understand the point of this.

If you want the mouse position just use mouse.x or mouse.y. you dont need to store it in a variable it already is in a variable.
Title: Re: Making an int change with mouse movement...
Post by: Matti on Wed 02/12/2009 19:15:59
He wants to measure the mouse movement, the mouse coordinates don't suffice for that.