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

Author Topic: Am I doing something wrong? I can't get Shapes to draw.  (Read 2762 times)

0 Members and 1 Guest are viewing this topic.

MarthKoopa

  • Guest
Am I doing something wrong? I can't get Shapes to draw.
« on: June 18, 2010, 07:24:08 am »
Code: [Select]
Shape hpBar;
Shape mpBar;
Shape xpBar;
hpBar.Rectangle( 50, 30, Player.HP + 50, 16, Color(0, 255, 0), 1, Color(255, 255, 255) );
mpBar.Rectangle( 50, 60, Player.MP + 50, 16, Color(0, 0, 255), 1, Color(255, 255, 255) );
xpBar.Rectangle( 50, 90, Player.XP + 50, 16, Color(255, 0, 0), 1, Color(255, 255, 255) );


That's how I set them up, then I just draw them to the screen like everything else.

Code: [Select]
Screen.Draw(hpBar);
Screen.Draw(mpBar);
Screen.Draw(xpBar);


I'm using SFML 2.0 with VC++ 2008

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Re: Am I doing something wrong? I can't get Shapes to draw.
« Reply #1 on: June 18, 2010, 08:08:54 am »
Quote from: "MarthKoopa"
That's how I set them up, then I just draw them to the screen like everything else.


And what happens? Does everything else draw correctly?

Are you calling Display()? :wink:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Am I doing something wrong? I can't get Shapes to draw.
« Reply #2 on: June 18, 2010, 08:12:38 am »
Read the doc and examples carefully, Rectangle is a static function which returns the created shape
Code: [Select]
hpBar = sf::Shape::Rectangle(...);
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Am I doing something wrong? I can't get Shapes to draw.
« Reply #3 on: June 18, 2010, 08:31:02 am »
You can create shapes on the fly without exploding the memory, they will properly get destroyed when exiting their scope.

But this is not an efficient strategy. You'd better create your bars once, with a 1 pixel width, and simply use the X scale to adjust the width dynamically according to the player's attributes (note that this is not going to work in SFML 1.6, though :D).

Quote
And is there an easier way to make the bars fill up to a certain point without having to put a second one under the frame?

Nop.
Laurent Gomila - SFML developer

 

anything