Windows When healthbar set in the left corner doesnt work correctly

C

CrashPoL

Guest
So I've recently joined this community and made a post and got help very fast so I have a new question. I have made some healthbar but I dont know what is wrong because the sprite is good, but I want a rectangle on the healthbar that let see losing hp when getting hit. My problem is when I set the coordinates of the rectangle to x-500 and y-379 or something like that and the second rectangle coordinates to x-120 en y -369 just for example the bealthbar start instead of losing hp adding or it starts losing hp and then goes to - so it leaves healthbar and start drawing health after healthbar. I want the health bar to follow the camera that follows player and that is in the left corner.
oCamera create event:
Code:
/// @description Set up camera
cam = view_camera[0];
follow = oPlayer;
view_w_half = camera_get_view_width(cam) * 0.5;
view_h_half = camera_get_view_height(cam) * 0.5;
xTo = xstart;
yTo = ystart;

shake_lenght = 0;
shake_magnitude = 0;
shake_remain = 0;
buff = 32;

draw_health = 0;
oCamera step event:
Code:
/// @description Update Camera

//Update destination
if (instance_exists(follow))
{
    xTo = follow.x;
    yTo = follow.y;
}

//Update object position
x += (xTo - x) / 15;
y += (yTo - y) / 15;

//Keep camera center inside room
x = clamp(x,view_w_half+buff,room_width-view_w_half-buff);
y = clamp(y,view_h_half+buff,room_height-view_h_half-buff);

//Screen shake
x +=random_range(-shake_remain,shake_remain);
y +=random_range(-shake_remain,shake_remain);
shake_remain = max(0,shake_remain-((1/shake_lenght)*shake_magnitude));

//Update camera view
camera_set_view_pos(cam,x-view_w_half,y-view_h_half);
oCamera draw event:
Code:
draw_sprite(sHealtBar,0,x+10,y+10)

if !instance_exists(oPlayer) exit;

draw_health = lerp(draw_health, oPlayer.hp, .25);

draw_set_color(c_red);
draw_rectangle(x+14, y+14, x+133*draw_health/oPlayer.maxhp, y+21, false);
draw_set_color(c_white);
game_ss.png

Thanks for any help!

Regards,
CrashPoL
 

Paskaler

Member
Try using Draw GUI Event to draw GUI elements instead of the draw event and remove all the x and y from the calculations in the event. In the Draw GUI event 0,0 is always top left corner of the screen, no matter where the canera is, while in the Draw event 0,0 is top leftof the room.
 
C

CrashPoL

Guest
Try using Draw GUI Event to draw GUI elements instead of the draw event and remove all the x and y from the calculations in the event.
Thanks for such fast reply, I'll try it and tell if it works or not!
 
Top