Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 892 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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
Offline wreed12345

JGO Knight


Medals: 24
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: 24
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.

Online HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


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


« 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.

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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

Was I before Chuang Tzu who dreamt about being a butterfly, or am I now a butterfly who dreams about being Chuang Tzu?
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.

CogWheelz (7 views)
2014-07-30 21:08:39

Riven (20 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!