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

Author Topic: [Solved] v1.6 sf::Shape gets drawn in the wrong position  (Read 2880 times)

0 Members and 1 Guest are viewing this topic.

adikid89

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - adikid89@yahoo.com
    • View Profile
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« on: March 08, 2011, 06:31:55 pm »
Image is pretty self explanatory..



What's going on?  :shock:

The big shape draws the smaller shape
Code: [Select]

void Widget::Draw()
{
if(!s_window) return;

s_window->Draw(m_shape);

//also draw children if any
for(WidgetList::iterator it = m_widgets.begin(); it != m_widgets.end(); it++) {
it->second->Draw();
}
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #1 on: March 08, 2011, 06:59:30 pm »
Do you use scale factors?
Laurent Gomila - SFML developer

adikid89

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - adikid89@yahoo.com
    • View Profile
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #2 on: March 08, 2011, 08:10:10 pm »
Quote from: "Laurent"
Do you use scale factors?

Scale factors .. as in did I use the shape.Scale() function? No.. I didn't scale or rotate or anything.. just a drew simple shape..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #3 on: March 08, 2011, 08:37:09 pm »
Ok, so this is probably not a bug. You should show us your code; or better: a minimal and complete piece of code that reproduces this problem.
Laurent Gomila - SFML developer

adikid89

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - adikid89@yahoo.com
    • View Profile
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #4 on: March 08, 2011, 10:55:51 pm »
I think I know what's wrong... it's probably just because I'm using the sf::Shape wrong... I'm not exactly sure how I'm supposed to use it...
Code: [Select]

        sf::Shape s1,s2;
s1 = sf::Shape::Rectangle(50,50,100,100,sf::Color(255,0,0));
s2 = sf::Shape::Rectangle(0,0,50,50,sf::Color(0,255,0));

s1.SetPosition(0,0);
s2.SetPosition(10,10);

I'd think this would make two 50 by 50 pixels rectangles, one at 0,0 and one at 10,10. This is not actually how it works... I'll get instead two 50,50 rects, one at 10,10(green), and one at 50,50(red).

So how should I actually use the shape? Should I normalize the params to the shape so that it'll be at 0,0 ?
like: s1 = sf::Shape::Rectangle(50,50,100,100,sf::Color(255,0,0));
to:   s1 = sf::Shape::Rectangle(0,0,50,50,sf::Color(255,0,0));

I didn't think the pos of the params actually matter.. because you can always just use the SetPosition function to move it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #5 on: March 09, 2011, 08:07:18 am »
They are two different things. The position that you pass in the "constructor" define the local position of the points, relative to the shape's global position. So later when you change this global position, it adds to the local position of the shape's points.
Laurent Gomila - SFML developer

adikid89

  • Newbie
  • *
  • Posts: 13
    • MSN Messenger - adikid89@yahoo.com
    • View Profile
[Solved] v1.6 sf::Shape gets drawn in the wrong position
« Reply #6 on: March 09, 2011, 09:21:31 am »
I see.. Thanks! I got it working now(by making sure local position is 0,0).

 

anything