• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Slider Bar Proportionate Display

D

Dackers

Guest
[Solved] (I can't edit title)

I'm having a hard time putting together a display bar and I'm hoping someone here can point me in the right direction.

Okay, I have four slider bars, which go from 0 to 100 (actually 0 to 1, but I multiply by 100 and round to display it as a percentage). The slider bars use a sprite with two subimages of the same size but different colors and the draw_sprite_part() function to display the correct proportion of the slider (green and red, where red is the default color and more green shows as I move the slider from left to right). I have a parent object with all of the code, and then child objects for each of the four sliders.

The problem I'm having is displaying the proportionate share of the each slider. I'd like to use a multi-colored bar with each slider value being displayed as its own color, proportionate to the total combined value. I can calculate the proportionate share and display it as a percentage (e.g., if all four bars are at 100%, each is 25% of the total combined value), but I'm having a brain fart on creating a display bar with the correct proportions.

I thought I'd set up a rectangular sprite with four subimages (each representing a slider bar's value) and then use the draw_sprite__part() function to draw the correct color in its proportionate size. As psuedocode it'd be like this:

Code:
draw_sprite_part(sprite_index, subimage_of_color_assiged_to_that_slider_bar, 0, 0, sprite_width*slider_value, sprite_height, end_of_preceding_bar, y;
I'm not sure the best way to loop through this and figure out the end of the preceding colored bar so that i can display the next bar.

Basically the slider and display bar would operate very similarly to the sliders in the game Game Dev Tycoon. I may have made a mess of explaining this, so please let me know if I'm missing some info.

Gamemaker 2 2.1.4.218
 
Last edited by a moderator:
D

dannyjenn

Guest
I've never played Game Dev Tycoon, but I take it you want to draw four partial bars side by side, touching each other, as if to form a single large bar?
For this, I wouldn't even use a loop. I'd just do something like this:
Code:
// create event:
bar1_width = sprite_get_width(spr_bar1) / 4; // be sure to divide by 4
bar2_width = sprite_get_width(spr_bar2) / 4;
bar3_width = sprite_get_width(spr_bar3) / 4;
Code:
// draw event:
var bar2_x = x+(bar1_width*bar1_slider_value);
var bar3_x = bar2_x+(bar2_width*bar2_slider_value);
var bar4_x = bar3_x+(bar3_width*bar3_slider_value);
draw_sprite_part(spr_bar1,bar1_color,0,0,bar1_width*bar1_slider_value,sprite_height,x,y);
draw_sprite_part(spr_bar2,bar2_color,0,0,bar2_width*bar2_slider_value,sprite_height,bar2_x,y);
draw_sprite_part(spr_bar3,bar3_color,0,0,bar3_width*bar3_slider_value,sprite_height,bar3_x,y);
draw_sprite_part(spr_bar4,bar4_color,0,0,bar4_width*bar4_slider_value,sprite_height,bar4_x,y);
 
Last edited by a moderator:
D

Dackers

Guest
Thank you! I was overcomplicating it. Your solution worked!
 
Top