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

Author Topic: Using an int in sf::Vector2i  (Read 3121 times)

0 Members and 1 Guest are viewing this topic.

Chay Hawk

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Email
Using an int in sf::Vector2i
« 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?

AFS

  • Full Member
  • ***
  • Posts: 115
    • View Profile
Re: Using an int in sf::Vector2i
« Reply #1 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)

 
« Last Edit: August 21, 2014, 06:51:12 am by AFS »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Using an int in sf::Vector2i
« Reply #2 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?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything