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

Author Topic: Filling a Meter  (Read 1627 times)

0 Members and 1 Guest are viewing this topic.

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Filling a Meter
« on: August 09, 2014, 08:17:37 pm »
Look at this sprite sheet:


It is a meter, that fills with orange. The meter represents energy. As energy gets above 10-20-30%, the sprite animates to the appropriate part of the texture.
I was wanting to make it so the orange fill would fill continuously, not in a discrete fashion like it is now. This would be easy if the meter was a line. As I could just have a separate sprite underneath the meter, and as percentage of energy went up, an equation would dictate how much to stretch the orange background fill. But because it is in a circle, I can't think of any way to do it. Any suggestions?
« Last Edit: August 09, 2014, 08:20:42 pm by Strikerklm96 »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Filling a Meter
« Reply #1 on: August 09, 2014, 09:49:04 pm »
Since the orange segments are all the same, maybe it would help to think about how to draw one of those segments by itself (filled to some arbitrary percentage).  Drawing the entire meter just involves correctly positioning and rotating seven of those segments on top of a static image.

The simplest solution might be having a sprite sheet for a single segment of the meter transitioning from gray to orange pixel-by-pixel.  It doesn't look like you have that many pixels for it to transition through, so that should be practical.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Filling a Meter
« Reply #2 on: August 09, 2014, 10:52:14 pm »
A sprite to draw the background. For the filled part, a vertex array with the sf::TriangleFan primitive type to create a fraction of the full circle, depending on the energy percentage. Then it's just a matter of calculating the proper texture coordinates for each vertex.
Laurent Gomila - SFML developer

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Filling a Meter
« Reply #3 on: August 10, 2014, 09:52:50 pm »
I made this image for how I understood what you said.


The text got messed up so here it is:
To fill the game object radially, rotate the fanned texture coordinates into the color fill.
That is what you said to do right?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Filling a Meter
« Reply #4 on: August 10, 2014, 10:24:24 pm »
I'm not sure how to interpret your image ;D and I don't have the time to make one to better explain what I mean, sorry.

The idea is not complicated. There are two images involved: a background, which is a static circle, easy to draw (a simple sprite for example), and the filled part, on top of the background, which is a circle too but not full. Fortunately, such a shape is straight-forward to create with a vertex array of type sf::TriangleFan. The only "tricky" part is to calculate the texture coordinates for each point. You can have the precision that you want, even 1 point for every energy percent would not be a lot (100 points for a single shape is more than ok for your graphics card).
Laurent Gomila - SFML developer