I sent mine to Sol to put on the Engines topic.. they're free and "pretty good".. so just hang on if you want to use one of them.
To make your own, here are my suggestions. You'll need two global variables (such as
global.hearts and
global.totalhearts) which are between 0 and 20, and change in increments of 0.25. You'll also need sprites. I'd recommend using one sprite with 5 subimages; empty, 1/4, 1/2, 3/4, and full, in that order.
Make an object that will be your "Heart engine". In its Draw event, the number of hearts you'll want to draw is the value of
global.totalhearts, rounded down. For example, if you have 12 hearts and 3 heart containers (global.totalhearts==12.75) you'd still just draw 12.
So, make a for-loop!
for (i=0; i<floor(global.totalhearts); i+=1) {
For every iteration of
i, you'll have to check which subimage to draw, and where to draw it. You can get the value of the current heart from
global.hearts-i. If it's less than or equal to 0, this heart is empty. Greater than or equal to 1, and it's full.
subimg = global.hearts - i
if subimg<0 { subimg=0 }
else if subimg>1 { subimg=1 }
For the position of the heart, start by making it relative to the view. Let's say you want the hearts to start 16 pixels from the left edge and 32 from the top edge:
heartx = view_xview[0] + 16 + ...
hearty = view_yview[0] + 32 + ...
And let's say for instance that each heart should be 8 pixels apart, in rows of 10. You might think to add
+ (i * to the first line, BUT, that will keep drawing on the same line after 10 hearts. Check out the
mod and
div operators.
mod gives you the remainder when one number is divided by another (good for the x position) and
div gives the total number of times one number divides into the other (good for the y position).
heartx = view_xview[0] + 16 + ((i mod 10) * 8)
hearty = view_yview[0] + 32 + ((i div 10) * 8)
Then, just draw the sprite! And end the loop, of course.
draw_sprite(sprHeart, subimg, heartx, hearty)
}