Need help keeping cursor inside object.

I

idunno

Guest
Hello!

How can I keep cursor inside an object?

For example, I have a volume slider and I want to keep cursor inside it until mb_left is released.
I'm also going to hide the cursor and change a sprite of the slider.

But first i want to figure out how to keep the cursor inside the slider when mb_left is down.

I tried to figure this out by myself and with help of google but still couldn't do it as I just started practicing GM.

It can be done with clamp, right?

Thanks for help!

ps. keep it simple, im newbie
 

samspade

Member
I've never tried this, so someone else may have better advice, but I believe the following is what you need (in GMS 2):

display_mouse_set(x, y);

Something like this might work:

Code:
if (clicked) {

    var xx = mouse_x;
    xx = clamp(xx, slider_x_min, slider_x_max);

    var yy = mouse_y;
    yy = clamp(yy, slider_y_min, slider_y_max);

    display_mouse_set(xx, yy);

}
Clicked should be however you determine that you've clicked the slider and are holding down the mouse button. slider_x/y_min/max should be however you're determining the width/height of the slider.
 

Ralucipe

Member
Just out of curiosity - what exactly is requiring you to lock down the position of the mouse cursor?

For a slider, you would probably be better off allowing free motion of the cursor, and then simply having the slider position change when mouse_x changes (or mouse_y, if your slider bar is vertical).
 
Top