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

Author Topic: GetPosition for shapes and sprites  (Read 3305 times)

0 Members and 1 Guest are viewing this topic.

Nerolat

  • Newbie
  • *
  • Posts: 3
    • View Profile
GetPosition for shapes and sprites
« 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);

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: GetPosition for shapes and sprites
« Reply #1 on: November 27, 2012, 06:56:20 pm »
And? Until you call SetPosition, GetPosition will return the default position which is (0, 0).
Laurent Gomila - SFML developer

Nerolat

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: GetPosition for shapes and sprites
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10823
    • View Profile
    • development blog
    • Email
Re: GetPosition for shapes and sprites
« Reply #3 on: November 27, 2012, 10:43:39 pm »
Stupid of me. I thought first args of constructor are pos.
Well RTFM! 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nerolat

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: GetPosition for shapes and sprites
« Reply #4 on: December 01, 2012, 06:03:10 pm »
Stupid of me. I thought first args of constructor are pos.
Well RTFM! 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.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: GetPosition for shapes and sprites
« Reply #5 on: December 01, 2012, 06:06:21 pm »
None, use sf::vertices directly for that.
Back to C++ gamedev with SFML in May 2023

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: GetPosition for shapes and sprites
« Reply #6 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_1VertexArray.php
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!