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

Author Topic: How to make my own "progress bar"?  (Read 5640 times)

0 Members and 1 Guest are viewing this topic.

Lambert

  • Newbie
  • *
  • Posts: 8
    • View Profile
How to make my own "progress bar"?
« on: September 22, 2013, 03:46:00 pm »
I want to create something like progress/loading bar, with custom texture. Depending on current value of certain variable, it would increase/decrease. I thought about resizing sprite, but it won't work if I will create circular indicator (like a circle around some icon). Any ideas?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How to make my own "progress bar"?
« Reply #1 on: September 22, 2013, 03:50:47 pm »
If you want a normal straight textured progress bar, use a texture that is 1 pixel wide. Then repeat the texture to fill your progress bar depending on how wide your bar is and the percentage complete. You should also wrap your progress bar in one class to make it reusable :D

If you want a form of a circular progress bar your better off making multiple textures with different percentages complete and then drawing the texture depending on the progress. Or you could get more dynamic with this method using only 1 texture, but that gets more complicated. It would be the same as the straight progress bar, but you would need to rotate and draw your 1 pixel wide texture multiple times.
« Last Edit: September 22, 2013, 03:56:18 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How to make my own "progress bar"?
« Reply #2 on: September 22, 2013, 04:02:18 pm »
Not sure what you mean with "custom textures", but you could create a texture of a fully filled bar and then simply change the texture rect, from 1px width to the full width, thus uncovering more and more of your texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make my own "progress bar"?
« Reply #3 on: September 23, 2013, 10:34:32 pm »
If you want any chance to success you need to do everything by your self.
Think about it multyple times before posting and try figure it on your own before asking for help.
If that fails we are here.

What you want to do is probably following
Make a sf::RectangleShape and set its sf::RectangleShape::setTexture(to texture of loadingbar)
then each loop sf::RectangeShape::setTextureRect(sf::IntRect(X,Y, Calculated progress, height))
Draw it.

I may not understand your question, its probably lack of information.
You require math to calculate how much of bar you need to draw or?
It above helps, am glad i could be of help, case else i tried.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0