Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Health bar?  (Read 7766 times)

0 Members and 1 Guest are viewing this topic.

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Health bar?
« on: May 22, 2011, 11:41:45 pm »
How would you display a simple health bar in SFML?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Health bar?
« Reply #1 on: May 22, 2011, 11:56:48 pm »
With a Sprite or Shape?

SFML is not a game engine so there is no direct magically working way to do it. You'll have to implement it yourself.

Anyway I would guess you either use a Sprite or Shape. You could use the SubRect on a Sprite to say "I only want to show this part of the image".
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

David

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Mmk
« Reply #2 on: May 23, 2011, 01:00:39 am »
I know that SFML is not a game engine (I came from actionscript)

But is there a way to do the same with a torus/doughnut-shaped health bar?

Spidyy

  • Sr. Member
  • ****
  • Posts: 493
    • View Profile
Health bar?
« Reply #3 on: May 23, 2011, 01:09:44 am »
For a Torus shape, you'll have to create your own Torus class, inheriting sf::Drawable.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Health bar?
« Reply #4 on: May 23, 2011, 01:52:03 am »
Or you could build it from concentric circles, if the inner circle needn't be transparent.

My library also contains a class for concave shapes, maybe it can help you (especially the Pie() function, which creates a sector of a circle).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jove

  • Full Member
  • ***
  • Posts: 114
    • View Profile
    • http://www.jestofevekites.com/
Health bar?
« Reply #5 on: May 23, 2011, 09:23:00 am »
My health bar uses a sprite and image showing what the full health will be.

I use SetScale to shrink the sprite on the X plane from 1 (full size) down to 0. Using a variable that ranges from 0 to 100 as health remaining, it's easy to convert that into SetScale.

Code: [Select]
Energy_Bar_Spr.SetScale(ship_energy / 100, 1);
{much better code}

AdventWolf

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
Health bar?
« Reply #6 on: May 25, 2011, 08:17:58 pm »
I have used
Code: [Select]

HealthBar.SetSubRect(sf::IntRect(0,0,int(currentHP/maxHP*229),14));


229 being the width, and 14 is the height of your sprite.