SFML community forums

Help => Graphics => Topic started by: AB on May 04, 2013, 01:02:52 pm

Title: How do I extract x and y from a Vector2f?
Post by: AB on May 04, 2013, 01:02:52 pm
sprite.getPosition() returns the x and y values of its position as Vector2f


Similarly, texture.GetSize() returns width and height as Vector2u.

I don't understand how I can extract the x and y values from Vector2f. How do I work with these?
Title: Re: How do I extract x and y from a Vector2f?
Post by: Nexus on May 04, 2013, 01:04:23 pm
It looks like you should read more about C++, because accessing the X and Y components is really straightforward.
sf::Vector2f vector;
float x = vector.x;
float y = vector.y;
Title: Re: How do I extract x and y from a Vector2f?
Post by: AB on May 04, 2013, 01:06:42 pm
It looks like you should read more about C++, because accessing the X and Y components is really straightforward.
sf::Vector2f vector;
float x = vector.x;
float y = vector.y;

Thanks. I understand the concepts but the info on http://www.sfml-dev.org/documentation/2.0/classsf_1_1Vector2.php is just confusing for me.
Title: Re: How do I extract x and y from a Vector2f?
Post by: Nexus on May 04, 2013, 01:11:11 pm
What exactly is confusing?

There are three public member functions, namely the different constructors.
There are two public attributes, namely x and y.
There are many free member functions, namely the operators.
Title: Re: How do I extract x and y from a Vector2f?
Post by: AB on May 04, 2013, 01:15:05 pm
What exactly is confusing?

The <T>'s. And the <U>
Title: Re: How do I extract x and y from a Vector2f?
Post by: Nexus on May 04, 2013, 01:17:10 pm
Those are template parameters. As mentioned, you should learn more about C++ before using SFML ;)