This site requires JavaScript, please enable it in your browser!
Greenfoot back
KitKat_KVIII
KitKat_KVIII wrote ...

2018/5/15

How do i show a health bar on an enemy?

KitKat_KVIII KitKat_KVIII

2018/5/15

#
Hi, I've created a heath bar for my hero that stays at the top of the world while my Hero moves around and updates as my Hero loses health. Currently my enemies have a health of 5 that gets deducted by 1 each time its shot, however you can't tell you've hit it till all 5 lives have been removed. I was wondering whether it was possible for an enemy to have a health bar attached to its image so that it follows it around screen? Hope this makes sense
danpost danpost

2018/5/15

#
KitKat_KVIII wrote...
I was wondering whether it was possible for an enemy to have a health bar attached to its image so that it follows it around screen?
Have each enemy create its own health bar and use (override) the addedToWorld method so that they can add the bar into the world. Have each enemy control the value and the position of its own health bar. You can add an act method to the health bar to remove itself from the world when zeroed. The enemy can remove itself when its health bar is found not to be in the world.
You need to login to post a reply.