SFML community forums

Help => General => Topic started by: Chay Hawk on August 21, 2014, 06:07:29 am

Title: Using an int in sf::Vector2i
Post by: Chay Hawk on August 21, 2014, 06:07:29 am
I have been looking all over for a way to use an int in vector 2i, how do i convert the int or use it in there? I couldnt find anything in the documentation or a google search so what do i do?
Title: Re: Using an int in sf::Vector2i
Post by: AFS on August 21, 2014, 06:48:20 am
I'm not really sure if I understand what you are asking. Anyway, I hope this helps:


// A Vector2i stores two ints.

sf::Vector2i myVector(10,10);   // Declares a vector with 10 and 10.
sf::Vector2i myOtherVector;     // Declares a vector without specifying values (so it will be 0 and 0 by default)

myVector.x = 20;   // Changes the first value of the first vector.
myVector.y = 30;   // Idem, but for the second value.

myOtherVector = sf::Vector2i(2,3);    // Another way of changing values. Now the second vector is 2 and 3 instead of 0 and 0.

std::cout << myVector.x << " " << myVector.y << "\n";  // Prints both values of the first vector (20 and 30)

 
Title: Re: Using an int in sf::Vector2i
Post by: Nexus on August 23, 2014, 09:28:39 pm
I have been looking all over for a way to use an int in vector 2i, how do i convert the int or use it in there?
sf::Vector2i is a typedef for sf::Vector2<int>, so it does already contain ints.

Can you reword your question and clarify it with a code example?