Then multiplying this by 2 makes a value between 0 and 2, which matches up with the sprites number of subimages.
GAME MAKER STUDIO HEALTH BAR FULL
Dividing their hp by their max hp gives their current hp as a decimal value of 0 to 1 (0 being dead, 1 being full health). You'll also notice I'm defining the subimage as (hp/maxHp) * 2. I use an instance variable for the offset so that each enemy can inherit this behaviour but have a different offset defined incase they're taller or shorter. This is so the healthbar will appear neatly above their head. Just use the "Draw Self" option under draw and you should be golden.ĭraw_sprite_ext( sHealthBar, (hp/maxHp) * 2, x, y + yOffset, (hp/maxHp), 1, 0, c_white, 1) Here I am drawing the health bar sprite at the enemy's x coordinates and at the enemy's y coordinates + a predefined offset (which I declare in the enemy's create event). One thing to note in the draw event is that when you do use it, the sprite assigned to the object disappears. The draw event with you code of what to draw will thus also execute 30 times a second.) (by default there are 30 images per second drawn to the screen. The draw event is the only event in which things can be drawn and draws every frame. The collision event checks if there is a collision with a certain object (It's code is literally executed on it's creation) The create event is the first thing executed on a object and is executed only once. The same thing can be roughly done for lives.Īll of the stuff you will actually need is inside of the score tab on the right and the only events you will need are create, step and draw.
Here are the steps that would need to be taken to make this:ġ.upon the creation of an object, give it a certain amount of health.Ģ.whenever there is a collision with another object decrease the health by 1.ģ.draw the health somewhere. However, some of these tutorials work exclusively with code so I'm going to make it simpler:
The bottom line is that you could have googled this yourself.