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

Author Topic: sf::Shape.SetPosition not properly working?  (Read 2925 times)

0 Members and 1 Guest are viewing this topic.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
sf::Shape.SetPosition not properly working?
« on: May 24, 2011, 10:58:03 pm »
Hallo everyone,

I'm doing the following:
Code: [Select]
while(app.IsOpened)
{
  //event proccessing omitted

  app.Clear();
  sf::Shape shape(sf::Shape::Rectangle(100,100, 150, 150, sf::Color::Green));
  //shape.SetPosition(0,0);
  app.Draw(shape);
  app.Display();
}


When I comment out the SetPosition line it is just a rectangle with coords 100,100,150,150.
But when I uncomment it i expect it to move to
0,0,50,50
But it just doesent move...
Why is that and what do I have to do to set the position to absolute coords?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Shape.SetPosition not properly working?
« Reply #1 on: May 24, 2011, 11:05:45 pm »
Shapes always have a global position of (0, 0) -- which is totally unrelated to where the shape's points are created. So changing the position to (0, 0) does nothing because it's already at (0, 0).

You shouldn't try to create a shape directly at its final positoin in the 2D scene if you plan to modify its position later. Create it at (0, 0) then play with SetPosition.
Laurent Gomila - SFML developer

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
sf::Shape.SetPosition not properly working?
« Reply #2 on: May 24, 2011, 11:12:35 pm »
thx for your fast response.
I fixed it now.

But could you please explain to me, why you did it like this?
Is this also true for sfml 2.0?

Imo this behaviour is quite counter-intuitive and its not mentioned in the docs of SetPosition, maybe you should add a little note for other people :-)

And one more question:
Does sf::Shape::Rectangle internally work by storing all points of the Rectangle?
I got this idea when I read the documentation of sf::Shape, as there are some point-modifying methods.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Shape.SetPosition not properly working?
« Reply #3 on: May 24, 2011, 11:26:57 pm »
Quote
But could you please explain to me, why you did it like this?

What other solution do I have?
- setting the global position automatically to the top-left corner point? no way
- forcing the top-left corner to be at (0, 0) and using a "size" argument instead of a full rectangle, in Shape::Rectangle? that would be weird

Quote
Is this also true for sfml 2.0?

SFML 2.0 will have a totally new drawables system, and -- oh yeeaahhhh -- nobody will have this kind of silly problem anymore.
But for now it's still the same, yes.

Quote
Does sf::Shape::Rectangle internally work by storing all points of the Rectangle?

Yes of course.
Laurent Gomila - SFML developer

 

anything