Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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 787 times)
0 Members and 1 Guest are viewing this topic.
Offline Slyth2727
« Posted 2013-04-23 01: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
-cMp

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Offline wreed12345

JGO Knight


Medals: 22
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #1 - Posted 2013-04-23 01: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-23 01: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: 22
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


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

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

Offline HeroesGraveDev

JGO Kernel


Medals: 212
Projects: 11
Exp: 2 years


If it wasn't Awesome, it wasn't me.


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

Screenshot please?

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

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

Offline Slyth2727
« Reply #6 - Posted 2013-04-23 03: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.

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Offline Slyth2727
« Reply #7 - Posted 2013-04-23 03:39:41 »

Davedes idea worked perfectly! Thank you very much, i am in love with this forum!!  Smiley

Check out Escaping Vox, a 3D
|\ _\  voxel based puzzler!
 \|_|
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org 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‑gaming.org
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!