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

Author Topic: SetCenter()  (Read 20001 times)

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetCenter()
« Reply #15 on: May 17, 2011, 10:10:23 pm »
Quote
Is it normal practice to initialize entity's at 0,0 and then move them where you want them?

Sure it is. It makes no sense to have the entity already offsetted relatively to its local origin. Sprites are implicitely created like this, and I think it works pretty well ;)
Laurent Gomila - SFML developer

tanders12

  • Newbie
  • *
  • Posts: 9
    • View Profile
SetCenter()
« Reply #16 on: May 18, 2011, 05:46:24 am »
Quote from: "Laurent"

If you call SetPosition(x, y), the top-left corner of your shape will move to (x, y).


With the following code:
Code: [Select]

line_start.x = x1;
line_start.y = y1;

line_end.x = 0 - ( Line_Length * cos( M_PI / 4 ) );
line_end.y = 0 - ( Line_Length * sin( M_PI / 4 ) );

Line = sf::Shape::Line ( 0,
                                     0,
                                     line_end.x,
                                     line_end.y
                                     Line_Thickness,
                                     Bounds_Color,
                                     Border_Width,
                                     Border_Color );

Line.SetPosition( line_start );


The top left corner of the line isn't moved to x1,y1 like you said. Instead the bottom right corner of the line is. I think it's because I'm using negatives to define the line from 0,0, correct? The reason I'm doing that is because the goal is to have a line of a given length displayed at a 160 degree angle.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetCenter()
« Reply #17 on: May 18, 2011, 07:44:39 am »
Yes you're right. I say "top-left corner" only as a shortcut, but in fact it's the point (0, 0).
Laurent Gomila - SFML developer

tanders12

  • Newbie
  • *
  • Posts: 9
    • View Profile
SetCenter()
« Reply #18 on: May 18, 2011, 07:52:09 am »
Ah ok. Well this is all still a bit confusing but it's working the way I expect now and I think I have a workable understanding of it. I'm sure as I work with things more it will eventually just click.

Thanks so much for your help Laurent and for making such an awesome library!

 

anything