• 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!

Score Bar that fills over time

Hi guys! I'm struggling on a problem that I have for serval days:
I want to do a bar that fills over time up to desired score (It's a vertical bar that fills to the bottom to the top). At the begining, a mini game is playing. During it, my bar is empty. After 5 seconds, the minigame ends, and here I want my bar to fill up little by little until the player's score. I can't use the draw_healthbar function because my bar has a special sprite. Instead, I use the draw_sprite_part function. I got an alarm that activates after 5 sec for the end of the mini game, and I tried to do someting with an alarm that activates itself every .1 seconds to fill my bar a little by little.
In my draw event, I got this line of code:
GML:
draw_sprite_part(spr_bar_fill, 0, 0, bar_top, fill_width, bar_height, xx,  (1-scr_percentage) * fill_height);
fill_width is the width of my sprite, not really important.
For bar_top and bar_height, I use this part of code:

Alarm 1 (Part):
Code:
alarm[2] = .1 * room_speed
Alarm 2 (Part) (i is set to 0 in the create event):
Code:
if i < scr_percentage * fill_height {
    i++;
    bar_top = fill_height - i;
    bar_height = i;
    alarm[2] = .1 * room_speed;
}
scr_percentage is my score in percent (there is a max score possible)
Here, I got... issues, the sprite isn't displayed with that code, and I don't really know where I fail, maybe because of an incorrect use of draw_sprite_part or the pseudo "for" statement done with the alarms.
If you have any question that might help me, don't hesitate! Thanks.
 
Last edited:
K

KiD_Rager

Guest
I'm assuming that the draw_sprite_part not working is the issue, ya?

Why not create a for loop in your Draw event, and in it use draw_sprite instead with variable i in the y-coordinate? So it may look something like:

GML:
var i;
for (i = 0; i < 10; i += 1)
   {
   draw_sprite(x, y - 16 * (i * 8), spr_bar_part);
   }
Then write a conditional IF statement for the max value of i you want.
 

TailBit

Member
You could use the percentage directly?

Test I did:
GML:
hh = sprite_get_height(sprite_index);
ww = sprite_get_width(sprite_index);

if variable_instance_exists(id,"scr_percentage") scr_percentage=min(1,scr_percentage+.005) else scr_percentage = 0;

draw_sprite_part(sprite_index, 0, 0, hh*(1-scr_percentage), ww, hh*scr_percentage, 0,  hh*(1-scr_percentage));
 
Top