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

Author Topic: Coordinates of Rect. I don`t know how to find them.  (Read 3642 times)

0 Members and 1 Guest are viewing this topic.

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Coordinates of Rect. I don`t know how to find them.
« on: November 16, 2013, 10:02:56 pm »
Pls help me with searching the function, that gives you coordinates of rect at the moment of asking( now it`s a rectangle shape ). I want to find thems and change it if any button is pressed. It probably the same as func :   s.move(X, Y), but it isnt what i need.. I looked at manuals and documentation and nothing more than   
const Vector2f& sf::Transformable::getPosition   (      )    const
get the position of the object

Returns
Current position
See Also
setPosition
There`re allot of information, so my young brain need a help.. Please :)
Oh, i have SFML 2,1.
« Last Edit: November 16, 2013, 10:11:10 pm by Salmon_Yo »

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #1 on: November 16, 2013, 11:43:26 pm »
The function that "gives you the coordinates of a rectangleShape at the moment of asking" is getPosition.
To set the position of a rectangleShape to another location, use setPosition or move. ???
setPosition is used in the first line of code of this tutorial.

BTW, your quote includes a "See Also: setPosition", which is a link you could have clicked on.

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #2 on: November 17, 2013, 08:43:47 am »
Nope, i knew it. Thank you. The question is how
shape.getPosition();
   work..

Like
sf::RectangleShape shp(sf::Vector2f(50, 50));

        shp.setPosition(0, 334);

        shp.setFillColor(sf::Color::Red);
       
       
       
       
        shp.getPosition(); // [color=red]after that i need X and Y of my rectangle in the console.. [/color]

       
        while (window.isOpen())
    {
    and lalala..
Probably i try to write something like that :
//
int x, y;
x=y=0;
shp.getPosition(x, y);
std::cout<<x<<y;

But getPosittion don`t call any arguments..

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #3 on: November 17, 2013, 11:23:03 am »
Read the documentation.

getPosition() returns the position (I don't know how the name could be more obvious), therefore you cannot pass the position as an argument to it.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Coordinates of Rect. I don`t know how to find them.
« Reply #4 on: November 17, 2013, 12:09:34 pm »
sf::Vector2f pos;
pos = shp.getPosition();
std::cout << pos.x << ", " << pos.y << std::endl;
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #5 on: November 17, 2013, 04:04:20 pm »
eXpl0it3r, thank you

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #6 on: November 17, 2013, 04:33:34 pm »
I'll never understand people. :-X

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #7 on: November 17, 2013, 04:41:12 pm »
Don`t be so sad.. English isn`t my first language, so it probably my mistake.. Thank you anyway for trying to help  ;)

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #8 on: November 17, 2013, 04:45:45 pm »
Yeah but if you didn't know how to use the resulting Vector2f from getPosition, why didn't you click on it in the doc and see how it worked? It's pretty simple and faster than asking on the forum.  ;)

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: Coordinates of Rect. I don`t know how to find them.
« Reply #9 on: November 17, 2013, 05:46:52 pm »
Yes, that`s stupid, but when i asked, u said nothing aboute vector 2f..

 

anything