Legacy GM Slider won't slide properly[Solved]

A

Artwark

Guest
I'm learning from SlasherXgames about sliders and I did one based on the tutorial here.


I am having the problem with the slider in that the slider doesn't show up from bottom. Instead it shows from the center and I can't raise the bar all the way fully up or down.

If you want to know the code that I've done, let me know but really, I just did the same thing as how the video shows.
 
Last edited by a moderator:
A

Artwark

Guest
Ok on second thought I'll just paste the code that I've written here...

For the bar

Create Event
Code:
randomize();

image_xscale = random_range(0.5,1);

image_yscale = image_xscale;

bottomlimit = y+(sprite_height/2)-(image_xscale*75);

toplimit = y-(sprite_height/2)+(image_xscale*75);

a = instance_create(x,y,obj_barslider);

a.image_xscale = image_xscale;

a.image_yscale = image_yscale;

a.barlength = sprite_height;

a.bottomlimit = bottomlimit;

a.toplimit = toplimit;

a.y = bottomlimit;
Mouse left pressed
Code:
if (mouse_y < bottomlimit) && (mouse_y > toplimit)

{

a.y = mouse_y;

}
For the slider
Code:
Create Event

yy =0;
grab = false;
percentage = 0;
Code:
Step Event

if (!mouse_check_button(mb_left))

{
grab = false;
}

if (grab = false)
{
exit;
}
else
{

if ((mouse_y + yy) < bottomlimit) && ((mouse_y + yy > toplimit))

{
y = mouse_y + yy;
}

else if((mouse_y + yy)>bottomlimit)

{
 y = bottomlimit;
}

else if((mouse_y + yy)<toplimit)

{
 y = toplimit;
}

percentage = round(((y-bottomlimit)/(toplimit-
bottomlimit))*100)

}
Code:
Left Pressed

grab = true;

yy = y-mouse_y;
Code:
Left Released

grab = false;
 

jo-thijs

Member
He mentioned in the video that you have to change the value 75 in these 2 lines:
Code:
bottomlimit = y+(sprite_height/2)-(image_xscale*75);
toplimit = y-(sprite_height/2)+(image_xscale*75);
to something lower in order to let the slider be able to raise the bar more.
Change 75 to 0 to allow the slider to range over the entire bar.

The code does create the slider at the bottom of the reachable bar for me,
so I'm guessing that issue will be fixed together with the previous issue.

Also, there are multiple things he's done just as example that you weren't supposed to take over, like these lines of code:
Code:
randomize();
image_xscale = random_range(0.5,1);
image_yscale = image_xscale;
 
S

Spartan121

Guest
Why dont use its in draw in obj_slider?
Code:
draw_sprite(spr_slider_line,0,xstart,ystart)
draw_self()
var slide=sprite_get_height(spr_slider_line)
x=clamp(x,xstart-(slide/2),xstart+(slide/2))
slider_dist=point_distance(x,ystart,(xstart+(slide/2))-slide,ystart)
 
A

Artwark

Guest
He mentioned in the video that you have to change the value 75 in these 2 lines:
Code:
bottomlimit = y+(sprite_height/2)-(image_xscale*75);
toplimit = y-(sprite_height/2)+(image_xscale*75);
to something lower in order to let the slider be able to raise the bar more.
Change 75 to 0 to allow the slider to range over the entire bar.

The code does create the slider at the bottom of the reachable bar for me,
so I'm guessing that issue will be fixed together with the previous issue.

Also, there are multiple things he's done just as example that you weren't supposed to take over, like these lines of code:
Code:
randomize();
image_xscale = random_range(0.5,1);
image_yscale = image_xscale;
But when I saw him do it at 75, he was able to raise the bar fully up...how come?
 
Top