Jump to content


Photo

Draw Health Bar


  • Please log in to reply
7 replies to this topic

#1 adam_jam man

adam_jam man

    GMC Member

  • New Member
  • 120 posts

Posted 01 March 2007 - 01:29 PM

how do you draw a health bar on top of an enemy and moving with the enemy and also make it separate. example: there is enemy 1 and enemy 2. enemy1 is the same object as enemy 2. but if i shoot enemy1 the health will decrease but enemy 2 will not decrease it would stay the same ok comprende :) ^_^ :GM069: he he he......
  • 0

#2 purple_pixie

purple_pixie

    GMC Member

  • New Member
  • 2647 posts

Posted 01 March 2007 - 01:51 PM

Righty ho.

To seperate their health (let's call it "hp") variables, just never change the value of "obj_enemy.hp" This applies to all obj_enemy's.

Instead, reference "hp" from the instance (e.g. on collision with bullet) or "other.hp" from another instance that has collided with it (e.g. on bullet collision with obj_enemy)

Now, to draw the healthbar:

2 options:

1) From the obj_enemy's draw event:
draw_healthbar(x-20,y-30,x+20,y-25,hp,c_black,c_red,c_green,1,0,0)

2) From a controller's draw event:
with obj_enemy
{
draw_healthbar(x-20,y-30,x+20,y-25,hp,c_black,c_red,c_green,1,0,0)
}

That do it for you?

Edited by purple_pixie, 01 March 2007 - 01:52 PM.

  • 0

#3 adam_jam man

adam_jam man

    GMC Member

  • New Member
  • 120 posts

Posted 01 March 2007 - 02:04 PM

so i just change the selfhealth to hp?
  • 0

#4 purple_pixie

purple_pixie

    GMC Member

  • New Member
  • 2647 posts

Posted 01 March 2007 - 02:29 PM

Or the hp to selfhealth - doesn't matter
  • 0

#5 _182360

_182360

    GMC Member

  • New Member
  • 1 posts

Posted 11 January 2011 - 06:55 PM

i used this code draw_healthbar(x-20,y-30,x+20,y-25,HP,c_black,
c_red,c_green,1,0,0) that you gave him but my enemy seems to disapeer what could i possible have done wrong
  • 0

#6 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 11 January 2011 - 07:31 PM

using the draw event cancels the built-in draw event.
You have to tell the game to draw the sprite, using draw_sprite.
  • 0

#7 Hokkaido

Hokkaido

    GMC Member

  • New Member
  • 114 posts
  • Version:GM8

Posted 03 July 2011 - 09:12 PM

Remember, you could also make a seperate draw event, call it object draw. Then set on the player a global.life, then go to the draw step event
x = obj_player.x
y = obj_player.y

And put the code for the drawings in the draw event.

Good luck =)
  • 0

#8 aaabbbccc

aaabbbccc

    GMC Member

  • GMC Member
  • 525 posts

Posted 03 July 2011 - 10:06 PM

http://www.youtube.c...nel_video_title
This is a tutorial on health bars. Enjoy.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users