GameMaker: Studio

GameMaker: Studio

データを表示:
Health bar problems!
Im making a 2 player Legend of Zelda game, but im having trouble with the health bar. The first time I tried to make it, if the 1st player got hurt it would affect the other players health bar too. Then I searched up a tutorial on youtube but when I tried that it wouldnt show my players, only the health bar. Does anyone know how to make 2 proper health bars that are on top of the players and follow the player and make the health bars seperate from each other?
Please Help!
< >
1-6 / 6 のコメントを表示
if it's only showing the health bar are you maybe forgetting to draw_self() or draw_sprite(). if you have something in the draw event you have to also tell it to draw itself.
Oh ok, I will try draw_self() and draw_sprite(). (sorry i have never done a health bar before.)
And it happened again. if the first health bar is affected, the 2nd one is too.
I need to start from scratch.
Sera 2014年3月8日 17時08分 
How are you altering the health? obj_Player.health -= whatever will deduct from every instance of obj_Player, for example.

Both player objects need to have their own health tracked individually. If you're using Game Maker's built in health variable, that thing is global, meaning it doesn't belong to any given object. You'll need your own varibale declared in the player object; it can just be Health and work fine, because GM is in fact case sensative.

From there, the easiest thing to do would probably be to have enemies and obstacles set to deal a specific amount of damage when they trigger a collision with the player objects; during collision events, there's a special term called other that works in code and is usually selectable in drag & drop that will automatically apply the action to whatever you've collided with.

So, for example, if a bullet has an event where it collides with the player and you want to remove 5 health, you could use the drag & drop's Variable command, select "Other" as the target, and set the player's HP to 5 less what it was by setting -5 for your value and checking "Relative." (Relative is important! It subtracts 5 from the present HP, whereas if it's left unchecked it wil just set the HP to -5.) After that, destroy the bullet, or it'll keep hitting your player every step until it passes through.

Alternatively, the same event with code would more or elss be like this:

other.HP -= 5; instance_destroy();

You could aloso do your collision events in the player objects, but that's going to start stacking and getting unweildly very quickly, so it would probably be a lot wiser to have whatever's trying to inflict damage look for its target rather than the other way around.

Hope this helps.
Ah, its you, I remember you from somewhere. Sorry, I should've posted, I got the Health bar working finally already. But thanks anyway! I also added a knockback effect on the player if an enemy hits him. Thanks Nok and Zaron! :D
< >
1-6 / 6 のコメントを表示
ページ毎: 1530 50

投稿日: 2014年3月8日 15時02分
投稿数: 6