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

GameMaker Health bar follow player

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:
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;*/
Step event
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)
Not sure how to procced with this, thanks in advanve
 
C

Crazy Star

Guest
Add x/y to the draw arguments like this:
Code:
draw_healthbar(x+200, y+150, x+500, y+230, pc, c_black, c_red, c_lime, 0, true, true)
 
R

Ragedleinad

Guest
Add x/y to the draw arguments like this:
Code:
draw_healthbar(x+200, y+150, x+500, y+230, pc, c_black, c_red, c_lime, 0, true, true)
That did not work for me but I just figured it out, better to draw it inside of "Draw Gui" event these are fix coordinates, thanks anyway ^^
 
Top