Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (672)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Centering Health Bar on Mob  (Read 1570 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-04-22 23:37:38 »

Alright, I know this seems like a simple math question, and to be perfectly honest, it is, but I for some reason cannot think of it right now, and my deadline is in a week and a half. Here's the question: I have a mob, as well as it's health bar, above it's head and I need to center it on the mob. The first thing that comes to line is healthBarX = x + (healthWidth / 2) ; but obviously this doesn't work because if the mobs health bar is longer than the width of the mob than it is wayyyy to the right. I know, silly question but help is very much appreciated
Offline wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

« Reply #1 - Posted 2013-04-22 23:40:57 »

Just to clarify, does the bar need to be recentered every time its health gets smaller? Maybe a picture of the bar could help

Offline Agro
« Reply #2 - Posted 2013-04-22 23:41:42 »

Can't you just put a red bar under the green bar? Red bar standing for max health and green bar standing for current health?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

« Reply #3 - Posted 2013-04-22 23:52:25 »

Yes that could work. Are you using any library with this? Either way this question would persist.

Offline HeroesGraveDev

JGO Kernel

Medals: 373
Projects: 11
Exp: 3 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #4 - Posted 2013-04-23 00:07:13 »

Screenshot please?

Offline davedes
« Reply #5 - Posted 2013-04-23 00:14:54 »

Assuming upper-left origin for rendering entities:
float barX = (entityX + entityWidth/2f) - barWidth/2f;
float barY = entityY - BAR_SPACING;

Offline Slyth2727
« Reply #6 - Posted 2013-04-23 01:36:27 »

I have the bar set up to be as long as the mobs health is. e.g, if the mobs health is 100, the bar is 100 px long. So I think davedes suggestion will work, props to him if it does, otherwise I will set it up to be a static length for all health and adjust to that.
Offline Slyth2727
« Reply #7 - Posted 2013-04-23 01:39:41 »

Davedes idea worked perfectly! Thank you very much, i am in love with this forum!!  Smiley
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (45 views)
2016-04-18 14:18:53

KaiHH (45 views)
2016-04-18 08:35:41

KaiHH (75 views)
2016-04-15 12:43:58

theagentd (78 views)
2016-04-14 02:16:17

theagentd (92 views)
2016-04-14 02:15:43

IanParcs (105 views)
2016-04-12 03:51:16

IanParcs (47 views)
2016-04-12 03:50:03

IanParcs (43 views)
2016-04-12 03:49:54

IanParcs (38 views)
2016-04-12 03:49:52

IanParcs (48 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!