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

Author Topic: GetPosition always zero  (Read 1656 times)

0 Members and 1 Guest are viewing this topic.

typpi_j

  • Newbie
  • *
  • Posts: 2
    • View Profile
GetPosition always zero
« on: March 04, 2010, 11:37:37 am »
Hey
I have following code:
Code: [Select]

    for (int i = 0; i < 16; i++)
    {
        T_BallItem item;
        item.radius = sf::Randomizer::Random(15.0f, 80.0f);
        item.ball = sf::Shape::Circle(sf::Randomizer::Random(0.0f, 800.0f),
                                          sf::Randomizer::Random(0.0f, 380.0f),
                                          item.radius,
                                          sf::Color(0, 128, 128));
        item.ball.SetBlendMode(sf::Blend::Multiply);
        items.push_back(item);
        std::cout << item.ball.GetPosition().x << "x" <<  item.ball.GetPosition().y  << std::endl;
    }


GetPosition() always returns 0 for x and y. What I am doing wrong?


PS. Is it possible to get circle radius somewhere? Now I do it with my own struct

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetPosition always zero
« Reply #1 on: March 04, 2010, 03:57:12 pm »
What you pass to sf::Shape::Circle are the local positions of the points, relative to the shape's origin. GetPosition returns the global position of the whole shape, which is zero because you never move it.

Quote
PS. Is it possible to get circle radius somewhere?

No, because what you get is a shape, not a circle. sf::Shape::Circle is just a helper function that creates a shape whose points are arranged in circle. After construction, a shape is just a set of points.
Laurent Gomila - SFML developer

typpi_j

  • Newbie
  • *
  • Posts: 2
    • View Profile
GetPosition always zero
« Reply #2 on: March 04, 2010, 07:54:17 pm »
Thank you. I got it working by using your advice.

 

anything