Creating slidebar

Im trying to create a slide bar. My problem is that when i drag the slider then let go of the mouse button the slider goes back to the start 0

im pre sure its because im setting sliderx inside function.
im not sure how to set the sliderx float from the sliderValue
Last edited on
Okay so we're just going to do some algebra to figure out how to calculate sliderx given SliderValue.

We know the following.

SliderValue = ((max - min) / (w))*(sliderx - x + sliderw / 2);

If we divide both sides by ((max - min) / (w)) we now have

SliderValue/ ((max - min) / (w)) = (sliderx - x + sliderw / 2);

If we add x to both sides we get

(SliderValue/ ((max - min) / (w)) ) + x = (sliderx + sliderw / 2);

And finally, if we subtract sliderw/2 from both sides we get

(SliderValue/ ((max - min) / (w)) ) + x - sliderw/2 = sliderx;

Therefore, we can calculate sliderx by doing

sliderx = (SliderValue/ ((max - min) / (w)) ) + x - sliderw/2;
Last edited on
omg thanks so much.

solved
Could you please click the check mark so that people can see that the topic was solved without clicking on it?

And no problem, glad I could help. :)
Sorry i have one small problem.

if i draw my slider with (min = 0, max = 100) it works fine
but if i draw it with (min = 50, max = 100) the sliders min ends up being 0 and the max ends up as 50
Topic archived. No new replies allowed.