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

Author Topic: [Solved] sf::Shape::Line not drawing a line  (Read 1697 times)

0 Members and 1 Guest are viewing this topic.

Naxos

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Solved] sf::Shape::Line not drawing a line
« on: September 17, 2009, 08:41:28 pm »
I'm trying to draw some simple lines using the Line() function of sf::Shape.

However, I get no rendering of lines on the screen.

Here's how I'm doing it at the moment:

Code: [Select]

sf::Shape line;
for(unsigned int i=0;i<layout.size();++i)
{
// get 1st point for line
LayoutPoint p = layout.getPointAt(i);

sprDiamond.SetPosition( p.x, p.y );
App.Draw( sprDiamond );  // this draws no problem

// get 2nd point for line ( % size() because the lines are drawing a 'track' of sorts )
LayoutPoint n = layout.getPointAt( (i+1) % layout.size() );

line.Line( p.x, p.y, n.x, n.y, 10.0f, sf::Color(127,127,127,127) );
App.Draw( line );
}


So I get my positions drawing diamonds, but the lines between each diamond are not being draw.

Am I doing something incorrectly here?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
[Solved] sf::Shape::Line not drawing a line
« Reply #1 on: September 17, 2009, 09:08:28 pm »
Nice nickname. :)

sf::Shape::Line() is a static method which creates a new shape containing a line and returns it. See the documentation. So, you have to assign it to a sf::Shape instance. I guess, you will need a STL container to store multiple lines.

I had problems with this issue at the beginning, too. I think, it's not very clear that the Line() member-function is static. Something like CreateLine() would be more expressive in my opinion.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Naxos

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Solved] sf::Shape::Line not drawing a line
« Reply #2 on: September 17, 2009, 09:35:29 pm »
Thanks Nexus :)

I should've noticed that myself, geez.

For the moment I'm just saying:

Code: [Select]
App.Draw( sf::Shape::Line( p.x, p.y, n.x, n.y, 10.0f, sf::Color(127,127,127,127) ) );

And that works. I suppose a container would be more efficient time-wise, but I'll leave it like this unless it starts to affect performance.

Thanks again!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
[Solved] sf::Shape::Line not drawing a line
« Reply #3 on: September 17, 2009, 10:09:31 pm »
For a single line, you don't even need a container. But instead of creating the sf::Shape instance every frame, you could declare it anywhere it lasts (for example as a class member, or outside the main loop). Then you just call App.Draw(MyLine); where MyLine is your variable.

Although this won't make a difference in your case, you could keep it in mind for later, if performance becomes more important. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything