R
Ragedleinad
Guest
Hi team, I want to have the health bar to follow the player when he moves but I can't get it to work.
My camera objecta (oCamera) has:
Create event:
Step event
This will follow the player, now for my basic health bar object oHealthBar
Draw Event
Not sure how to procced with this, thanks in advanve
My camera objecta (oCamera) has:
Create event:
Code:
/// @description update camera
// You can write your code in this editor
//Camera by default
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 and yto are the coordinates we are moving to
xTo = xstart;
yTo = ystart;
/*xTo = x;
yTo = y;*/
Code:
/// @description Insert description here
// You can write your code in this editor
if(instance_exists(follow))
{
xTo=follow.x;
yTo=follow.y;
}
//Update object position
x += (xTo - x) / 25;
y += (yTo - y) / 25;
//Update camera view
//clamp is to make sure player view doesnt go out of the widht of room
x = clamp(x,view_w_half,room_width-view_w_half);
y = clamp(y,view_h_half,room_height-view_h_half);
camera_set_view_pos(cam,x-view_w_half,y-view_h_half);
// You can write your code in this editor
This will follow the player, now for my basic health bar object oHealthBar
Draw Event
Code:
/// @description Insert description here
// You can write your code in this editor
var pc;
pc = 100;
draw_healthbar(200, 150, 500, 230, pc, c_black, c_red, c_lime, 0, true, true)