[SOLVED] Locking mouse movement to slider

Started by Stapper, Thu 05/10/2017 04:31:30

Previous topic - Next topic

Stapper

Hi all,


I made a mini-game involving a slider that needs to be held at a certain value to complete it. It works great but currently you can exploit this by simply setting the cursor to the correct value and waiting it out.

Is it possible to prevent the player from setting the cursor? Or better yet, can I somehow tie the movement of the slider to the movement of the mouse (like moving the mouse up will move the slider at the same time)?


I hope that describes my problem clear enough...

eri0o

You can just set your slider and make it's GUI not clickable.

Code: ags

function repeatedly_execute(){
  if(GUI_With_Slider.Visible=true){
    slider.Value = (mouse.y*(slider.Max-slider.Min))/System.ViewportHeight;
  }
}


Could you show the code of what you have?



Stapper

Wow that is quite the trick! Thanks a lot man!

It works well to control the slider, only it comes with two problems:
1. I cannot select the highest value, as my mouse doesn't seem to go all the way to the screen edge.
2. It moves in reverse. As my mouse goes lower, the number increases, thus making the slider go up.

Any way to fix these problems?

Oh and I used your code exactly like you mentioned:
Code: ags
function room_RepExec()
{
  if (gSSD.Visible == true) {
    sldSSD.Value = (mouse.y*(sldSSD.Max-sldSSD.Min))/System.ViewportHeight;
  }
}

Khris

It's a linear function: sldSSD.Value = m * mouse.y + t

I) sldSSD.Max = m * 0 + t
II) sldSSD.Min = m * (System.ViewportHeight - 1) + t

t = sldSSD.Max

sldSSD.Min - sldSSD.Max = m * (System.ViewportHeight - 1)
m = (sldSSD.Min - sldSSD.Max) / (System.ViewportHeight - 1)

Code: ags
function room_RepExec() {
  if (gSSD.Visible == true) {
    sldSSD.Value = mouse.y * (sldSSD.Min - sldSSD.Max) / (System.ViewportHeight - 1) + sldSSD.Max;
  }
}

Stapper

OMG this works just perfectly!

Thanks a lot guys! :-D

SMF spam blocked by CleanTalk