Making an int change with mouse movement...

Started by Technocrat, Wed 02/12/2009 17:41:41

Previous topic - Next topic

Technocrat

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.

DoorKnobHandle

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):

Code: ags

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.

Technocrat

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!

Calin Leafshade

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.

Matti

He wants to measure the mouse movement, the mouse coordinates don't suffice for that.

SMF spam blocked by CleanTalk