SFML community forums

Help => Graphics => Topic started by: Nerolat on November 27, 2012, 06:55:28 pm

Title: GetPosition for shapes and sprites
Post by: Nerolat on November 27, 2012, 06:55:28 pm
Hello, I keep getting 0 from GetPosition().x and GetPosition().y everytime I use it. No matter if it is a sprite, a shpae or anything.
       
Quote
x = Rect.GetPosition().x;
        std::cout << x << std::endl; // Always prints 0;
Here is the line where I create that rectangle:
Quote
sf::Shape Rect = sf::Shape::Rectangle(0, 0, 20, 20, sf::Color::Red);
Title: Re: GetPosition for shapes and sprites
Post by: Laurent on November 27, 2012, 06:56:20 pm
And? Until you call SetPosition, GetPosition will return the default position which is (0, 0).
Title: Re: GetPosition for shapes and sprites
Post by: Nerolat on November 27, 2012, 06:57:38 pm
Thanks for reply, Laurent, however even if I set it to
Quote
sf::Shape Rect = sf::Shape::Rectangle(100, 100, 20, 20, sf::Color::Red);
It still returns 0. Using SFML 1.6

EDIT:

Stupid of me. I thought first args of constructor are pos.
Title: Re: GetPosition for shapes and sprites
Post by: eXpl0it3r on November 27, 2012, 10:43:39 pm
Stupid of me. I thought first args of constructor are pos.
Well RTFM (http://www.sfml-dev.org/documentation/1.6/)! it's so nice and easy understandable. ;)

Also I advise you to use SFML 2, because SFML 1.6 hasn't been touched over 2 years, has many bugs and lacks a lot of new and shiny features. :)
Title: Re: GetPosition for shapes and sprites
Post by: Nerolat on December 01, 2012, 06:03:10 pm
Stupid of me. I thought first args of constructor are pos.
Well RTFM (http://www.sfml-dev.org/documentation/1.6/)! it's so nice and easy understandable. ;)

Also I advise you to use SFML 2, because SFML 1.6 hasn't been touched over 2 years, has many bugs and lacks a lot of new and shiny features. :)

Thanks! You are my savior!

By the way, another question -
what shape should I use for lines? I thought there is a shape in SFML 2.0 especially made for lines.
Title: Re: GetPosition for shapes and sprites
Post by: FRex on December 01, 2012, 06:06:21 pm
None, use sf::vertices directly for that.
Title: Re: GetPosition for shapes and sprites
Post by: masskiller on December 01, 2012, 06:08:05 pm
Two vertexes or a VertexArray with sf::lines as a primitive should suffice.

Check this for more details:

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vertex.php (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vertex.php)

http://www.sfml-dev.org/documentation/2.0/classsf_1_1VertexArray.php (http://www.sfml-dev.org/documentation/2.0/classsf_1_1VertexArray.php)