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

Draw GUI Issue.

S

Samurai1506

Guest
In my game I added a healthbar that i want to be drawn on top of the players head, but drawing it in the normal draw event made it draw underneath some objects and i need it to draw on top of everything. So i made it in the draw GUI event. but now I am stuck. The healthbar keeps moving away and towards and just moves in all directions when its just supposed to be following the player. Any help would be greatly appreciated.


with this...Screenshot (50).png
 

Alexx

Member
Probably because your play area is bigger than the view. You'll have to adjust your GUI co-ordinates to be relative the player's position relative to the view.

You could try changing the depth after drawing the player, draw healthbar and reset the depth,
 

kburkhart84

Firehammer Games
Probably because your play area is bigger than the view. You'll have to adjust your GUI co-ordinates to be relative the player's position relative to the view.
That would be accurate if they were using the regular draw event, NOT the draw GUI event.

In my game I added a healthbar that i want to be drawn on top of the players head, but drawing it in the normal draw event made it draw underneath some objects and i need it to draw on top of everything. So i made it in the draw GUI event. but now I am stuck. The healthbar keeps moving away and towards and just moves in all directions when its just supposed to be following the player. Any help would be greatly appreciated.
Can you show me the code where you have in the draw GUI event? If you draw there, you should not be trying to follow the player or anything like that, as those positions in that event should be in relation to the GUI space only and won't change no matter what the player and views do.
 
S

Samurai1506

Guest
GML:
//Draw Player Healthbar

display_set_gui_size(480, 270);

draw_healthbar(obj_player.x-7, obj_player.y-15, obj_player.x+7, obj_player.y-14, obj_player.playerHp, c_black, c_red, c_green, 0, true, false);
 
S

Samurai1506

Guest
GML:
//Draw Player Healthbar

display_set_gui_size(480, 270);

draw_healthbar(obj_player.x-7, obj_player.y-15, obj_player.x+7, obj_player.y-14, obj_player.playerHp, c_black, c_red, c_green, 0, true, false);
 
S

Samurai1506

Guest
Draw Player Healthbar
display_set_gui_size(480, 270);
draw_healthbar(obj_player.x-7, obj_player.y-15, obj_player.x+7, obj_player.y-14, obj_player.playerHp, c_black, c_red, c_green, 0, true, false);[/CODE]
 

kburkhart84

Firehammer Games
There is your problem.

1. You don't need to set the gui size every frame, just set it once in some controller object at the beginning of your game, and base the rest of the gui off that same size.

2. You don't want the gui drawing to have anything at all to do with the player positions. The reason you switched to using the DrawGUI version of the draw event was to avoid having to try following the view around. Try something more like the following.

Code:
draw_healthbar(10, 10, 100, 20, obj_player.playerHp, c_black, c_red, c_green, 0, true, false);
That should draw a health bar in the upper left corner of the screen, and since it is in GUI space, not following the player or anything, it should stay right where it is just fine no matter where the player goes.
 
If the camera moves, then the health bar will move in ways you won't expect. Keep in mind that the GUI is static, it doesn't "move" like a camera would. 100,100 will always be the same place on the screen with the GUI layer no matter where the camera is, so if you want to use it to draw your health bars and such, you'll actually have to factor in the camera's coordinates as well.

Also, just set the GUI size once, probably when the game starts. No need to keep calling that function over and over.
 
Top