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:
oCamera step event:
oCamera draw event:
Thanks for any help!
Regards,
CrashPoL
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;
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);
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);
Thanks for any help!
Regards,
CrashPoL