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

Author Topic: How do I extract x and y from a Vector2f?  (Read 13347 times)

0 Members and 1 Guest are viewing this topic.

AB

  • Newbie
  • *
  • Posts: 19
    • View Profile
How do I extract x and y from a Vector2f?
« 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?
« Last Edit: May 04, 2013, 01:05:10 pm by AB »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do I extract x and y from a Vector2f?
« Reply #1 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;
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AB

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: How do I extract x and y from a Vector2f?
« Reply #2 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do I extract x and y from a Vector2f?
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AB

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: How do I extract x and y from a Vector2f?
« Reply #4 on: May 04, 2013, 01:15:05 pm »
What exactly is confusing?

The <T>'s. And the <U>

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How do I extract x and y from a Vector2f?
« Reply #5 on: May 04, 2013, 01:17:10 pm »
Those are template parameters. As mentioned, you should learn more about C++ before using SFML ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything