K
KC Frye
Guest
My heath meter object (which is a zelda-style heart system) has an animation that causes it to blink red when the player character is hit, so as to attract the attention of the player and alert them that they've been struck.
However, because I've set it up in the Draw GUI event, the object gets redrawn every step of the game, therefore the animation doesn't appear to run because it's constantly being restarted at the first frame. What is the best solution to fix this?
However, because I've set it up in the Draw GUI event, the object gets redrawn every step of the game, therefore the animation doesn't appear to run because it's constantly being restarted at the first frame. What is the best solution to fix this?
Code:
var width, xx, yy, xempty, yempty, xfull, yfull, xhalf, yhalf, xquarter, yquarter, xthreequarter, ythreequarter;
width = display_get_gui_width();
//x buffer between bubbles
xx = width - 36 * 6; //36 = health width (32) + buffer (4) //6 = # of health bubbles per row
//y buffer between top of screen and bubbles
yy = 24;
xempty = 0;
yempty = 0;
xfull = 0;
yfull = 0;
xhalf = 0;
yhalf = 0;
obj_player.maxhitpoints = clamp(obj_player.maxhitpoints, 6, 48);
obj_player.hitpoints = clamp(obj_player.hitpoints, 0, obj_player.maxhitpoints);
//----------------------------------------------------------------------------
//draw text
draw_set_color(c_white);
draw_text(width - (36 * 6) / 2, 0, "[L I F E]");
draw_set_halign(fa_left);
//--------------------------------------------------------------------------
//EMPTY BUBBLES
repeat(obj_player.maxhitpoints/2) {
if (xempty == 36 * 6) {
yempty = 36;
xempty = 0;
}
draw_sprite (spr_HealthEmpty, 7, xx + xempty, yy + yempty)
xempty += 36;
}
//HALF BUBBLES
repeat(floor(obj_player.hitpoints/2) + frac(obj_player.hitpoints/2) * 2)
{
if (xhalf >= 36 * 6) {
yhalf = 36;
xhalf = 0;
}
draw_sprite (spr_HealthHalf, 7, xx + xhalf, yy + yhalf)
xhalf += 36;
}
//FULL BUBBLES
repeat(floor(obj_player.hitpoints/2))
{
if (xfull >= 36 * 6) {
yfull = 36;
xfull = 0;
}
draw_sprite (spr_HealthFull, 0, xx + xfull, yy + yfull)
xfull += 36;
}
//----------------------------------------------------
with (obj_player){
if (keyboard_check_pressed(vk_up)) { ++hitpoints}
if (keyboard_check_pressed(vk_down)) { --hitpoints}
if (keyboard_check_pressed(vk_left)) {maxhitpoints += 2}
if (keyboard_check_pressed(vk_right)) {maxhitpoints -= 2}
}