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

(SOLVED) Heart and brain that act as if they were "filled" vertical bars.

M

MagnumVulcanos

Guest
So I have two sprites, one transparent outline of a heart and a red blob in the shape o the heart, when the first is put over the second and both get shown, what you get is a pretty nice effect of a red heart.
Now comes the part I don't know how to do:
When the health attribute is at 50% the sprite under the heart should only get it's bottom half rendered.
In other words, if I have 60 health out of 200, only the bottom 30% of the sprite should be drawn, assuming a sprite with 100 pixels of height, only 30 pixels from the bottom upwards should be drawn and the rest should be transparent or not drawn, in essence invisible.

The main problem comes from the fact that the heart is an irregular shape so scaling the sprite below (solid color) wouldn't work since you'd get what looks like an ugly deflated balloon instead of a bar of health that decreases.

Any help would be appreciated. I bought the humble bundle version of game maker studio if the version is important.
 

CloseRange

Member
to do this you need to use the function draw_sprite_part();
Just get the percent so:
Code:
percent = health / max_health;
And then multiply it by the height of the sprite:
Code:
new_height = percent *height;
and then draw that much of the heart with draw_sprite_part();
 
M

MagnumVulcanos

Guest
to do this you need to use the function draw_sprite_part();
Just get the percent so:
Code:
percent = health / max_health;
And then multiply it by the height of the sprite:
Code:
new_height = percent *height;
and then draw that much of the heart with draw_sprite_part();
That's exactly what I was looking for, works well, thanks mate.
 
Top