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

Author Topic: Life-/Mana-bar  (Read 13707 times)

0 Members and 1 Guest are viewing this topic.

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #15 on: August 30, 2010, 12:04:15 pm »
Ah k...after reading thorugh the posts a few times I now understood what you mean :) Sounds easy and good! I think I'll try it ;)

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #16 on: August 31, 2010, 12:49:06 pm »
Hm. I have some problem with setting the right SubRect. I tried it as BeSaladin said. If I want to have full life it works. But if I reduce life by 1 the lifebar is gone and can't be seen anymore :-o

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Life-/Mana-bar
« Reply #17 on: August 31, 2010, 04:57:02 pm »
Can u show some code ^^ !
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #18 on: August 31, 2010, 08:39:30 pm »
This is how I use it

Code: [Select]

void character::Dec_Life(int Damage,sf::Sprite& Lifebar)
{
m_life -= Damage;
Lifebar.SetSubRect(sf::IntRect(0,0,95, m_life / m_max_life * 190));
Lifebar.Move(0, (768 - 190 + ( 190 - (m_life / m_max_life * 190))));
}


m_life is an integer that represents the life. m_max_life is the maximum life you can have.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Life-/Mana-bar
« Reply #19 on: August 31, 2010, 11:53:10 pm »
You don't use the Move function correctly. The 2 paramaters of the Move function are offsets.
Try using the SetY function instead, as written in BeSaladin pics.

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Life-/Mana-bar
« Reply #20 on: September 01, 2010, 12:19:59 am »
Move function isn't like SetX and SetY functions becauce move function increase X and Y by the values u give in :!:

For example : If u use Move function of a sprite that have x= 800 and y= 500 as the following : sprite.move(800,900) then the new coordinates would be x = 1600 and y = 1700.
And u will not see it probably in the window ^^. :P

 :arrow: I council u to avoid calculating in parameters as u did before try this ^^ :

Code: [Select]

int y = 768 - 190 + ( 190 - (m_life / m_max_life * 190));//
Lifebar.SetX ( y ); //this is better ^^  
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #21 on: September 01, 2010, 12:19:37 pm »
Even though it seems there's something wrong :-/ No matter how much the life should be reduced. No matter if life is 0 or 50 or something else it always sets the position to 768!(Screenresolution: 1024x768)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Life-/Mana-bar
« Reply #22 on: September 01, 2010, 12:29:53 pm »
If both m_life and m_max_life are integers, m_life / m_max_life will always be equal to zero. You need to cast at least one operand to float, or write m_life * 190 / m_max_life.
Laurent Gomila - SFML developer

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #23 on: September 01, 2010, 01:01:04 pm »
Ah yes....I remember.. :D thx^^ works :)

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #24 on: September 01, 2010, 01:51:36 pm »
But what we have now looks like this ->

I think I have to do it the other way round. Now we cut off the bottom and set the sprite lower. But it has to cut off the top!

I messed around with different rects, but somehow I don't get it O_o

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Life-/Mana-bar
« Reply #25 on: September 01, 2010, 05:06:37 pm »
If u see this line of code ^^ then it's so logical . :)

Code: [Select]
Lifebar.SetSubRect(sf::IntRect(0,0,95, m_life / m_max_life * 190));

Try this :

Code: [Select]
Lifebar.SetSubRect(sf::IntRect( 190 - ( m_life / m_max_life * 190 ) ,0,95,190));

It should work ^^.
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

Finn

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
Life-/Mana-bar
« Reply #26 on: September 01, 2010, 09:23:54 pm »
Actually....no :P
But I now finnaly figured out the right rect. :D Thank Rockstar Energydrink xD
Like this:
Code: [Select]

sf::IntRect NewRect(0,(190 - ( (float)m_life / m_max_life * 190 )),76,190);

BeSaladin

  • Newbie
  • *
  • Posts: 40
    • View Profile
Life-/Mana-bar
« Reply #27 on: September 02, 2010, 12:39:46 am »
hehe  :D sry for the erroe didn't pay attention on :F .
All i have is God's gift.
Tout ce que j'ai est un don de Dieu.

 

anything