jf_knight
Member
I'm following "SlasherXGames's" tutorial where his example shows the bar with values 0 to 100.
I would like to make a similar slider bar for my projects' global brightness setting that registers the values -1 on the far left, 0 at the very center, and +1 at the far right. (note: this bar is incremental, as there are more that just the three variables stated. It slides -1, -.99, -.98...etc)
I've reduced that there should probably be some editing in either the slide handle's step event:
Or the bar itself's create event:
What variables can I change to achieve this?
I would like to make a similar slider bar for my projects' global brightness setting that registers the values -1 on the far left, 0 at the very center, and +1 at the far right. (note: this bar is incremental, as there are more that just the three variables stated. It slides -1, -.99, -.98...etc)
I've reduced that there should probably be some editing in either the slide handle's step event:
Code:
//if the mouse button is not clicked
if (!mouse_check_button(mb_left))
{
grab = false;//slider is not clicked therefore not grabbed
}
if (grab == false) && (clicked == false)//if this object is not being grabbed
{
exit;
}
//otherwise change its coordinates
else
{
//if we slide within the constraints, update the sliders coordinate
if ((mouse_x + xx) > leftLimit) && ((mouse_x + xx < rightLimit))
{
x = mouse_x + xx;
}
else if ((mouse_x + xx) < leftLimit)//set at left limit if user wants to slide it too far left
{
x = leftLimit;
}
else if ((mouse_x + xx) > rightLimit)//set at right limit if user wants to slide it too far right
{
x = rightLimit;
}
}
//work out the percentage value
percentage = round(((x-leftLimit)/(rightLimit-leftLimit))*100);
clicked = false;
//calculate global.brightness
global.changeBrightness = percentage/100;
Or the bar itself's create event:
Code:
can_click = true;
rightLimit = x+(sprite_get_width(spr_slider_bar)/2)-30;
leftLimit = x-(sprite_get_width(spr_slider_bar)/2)+30;
//create the slider for this bar and assign it some values
a = instance_create(x, y, obj_brightness_slider_handle);
a.image_xscale = 1;
a.image_yscale = 1;
a.barLength = sprite_get_width(spr_slider_handle);
a.rightLimit = rightLimit;
a.leftLimit = leftLimit;
a.percentage = global.changeBrightness * 100;
//its current x value using the above percentage value
a.x = a.leftLimit + ((a.percentage/100) * (a.rightLimit-a.leftLimit));
a.clicked = false;
What variables can I change to achieve this?