F
fxokz
Guest
I tried to make a volume slider using slasherXgames tutorials and everything was going fine until i realised that the moment i slide the slider the volume percentage is clamped between 0 and 25 instead of 0-100
heres the code for both bar and slider
bar:
Slider:
Would anybody know why this would be happening?
heres the code for both bar and slider
bar:
Code:
Information about object: obj_hbar
Sprite: spr_bar
Solid: false
Visible: true
Depth: 100
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
randomize();
image_xscale = 2;
image_yscale = image_xscale;
left_limit = x-(sprite_width)+(image_xscale*75);
right_limit = x+(sprite_width)-(image_xscale*75);
a = instance_create(x, y, obj_hslider);
a.image_xscale = image_xscale;
a.image_yscale = image_yscale;
a.bar_length = sprite_width;
a.right_limit = right_limit;
a.left_limit = left_limit;
a.x = left_limit;
a.percentage = global.music_volume * 100;
a.x = a.left_limit + ((a.percentage/100) * (a.right_limit-a.left_limit));
Mouse Event for Left Pressed:
execute code:
if (mouse_x > left_limit) && (mouse_x < right_limit)
{
a.x = mouse_x;
}
Draw Event:
execute code:
draw_self();
draw_set_halign(fa_center);
draw_set_valign(fa_center);
draw_set_font(fnt_game);
draw_set_colour(c_white);
draw_text(x, y-55, "Volume");
Slider:
Code:
Information about object: obj_hslider
Sprite: spr_slider
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
image_index = 1;
image_speed = 0;
xx = 0;
grab = false;
percentage = 100;
Step Event:
execute code:
if (!mouse_check_button(mb_left))
{
grab = false;
}
if (grab = false)
{
exit;
} else
{
if ((mouse_x + xx) > left_limit) && (mouse_x + xx < right_limit)
{
x = mouse_x + xx;
} else if ((mouse_x + xx) < left_limit)
{
x = left_limit;
} else if ((mouse_x + xx) > right_limit)
{
x = right_limit;
}
}
percentage = round(((x - left_limit)/(x + right_limit))*100);
global.music_volume = percentage/100;
Mouse Event for Left Pressed:
execute code:
grab = true;
xx = x-mouse_x;
Mouse Event for Left Released:
execute code:
grab = false;
Draw Event:
execute code:
draw_self();
draw_set_halign(fa_center);
draw_set_valign(fa_center);
draw_set_font(fnt_game);
draw_set_colour(c_black);
draw_text(x, y, string(percentage));
Would anybody know why this would be happening?