Sign in to follow this  
null;

Healthbar structure for a game?

Recommended Posts

Should I have the healthbar itself in the player class or make a separate class for it?

 

Sorry this isn't a really long question and it's not very specific or detailed, but I just had a quick question.

Share this post


Link to post
Share on other sites

The health it's self can be in the player class.

However the "health bar" as in the visual format, should not be in the player class. It is a graphical element that scales the player's health from a range of 0.0 to 1.0, which is a percentage range.

 

This way the visual health bar is self contained and easier to debug.

Edited by Tangletail

Share this post


Link to post
Share on other sites

visual components should be separate from game logic. They only need to be updated once, before rendering, while game objects may be updated several times during a single frame's logic. Mixing visual components with game logic at best leads to needlessly cluttered code, and more likely will lead to many unnecessary updates of the visual components. Store health with the player, have health logic with the player class (if there isnt a more appropriate one), but keep all logic and data specific to the healthbar (not needed for game logic) separate.

Edited by nfries88

Share this post


Link to post
Share on other sites

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

 

I could see how this would apply to other stuff, too.

Share this post


Link to post
Share on other sites

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

 

I could see how this would apply to other stuff, too.

Yeah. I had to make sure to specify because who knows what you might be thinking if we all just said "keep the healthbar separate".

Share this post


Link to post
Share on other sites

 

Oh alright. So the actual math and health logic could be in the player class (prior assumption) and the visuals in a separate class. Got it.

 

I could see how this would apply to other stuff, too.

Yeah. I had to make sure to specify because who knows what you might be thinking if we all just said "keep the healthbar separate".

 

Well, that would have already kind of been implied in a way, but I get what you mean.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this