SFML community forums

Help => General => Topic started by: Bones on November 11, 2011, 07:36:33 am

Title: Trouble with sf::vector2
Post by: Bones on November 11, 2011, 07:36:33 am
Hello, I've been having trouble creating a variable for a vector.  Here's some pseudocode of what I would like to do:

vector2 vec(0,0)
vec.x = 1
vec.y = 5

I'm using SFML2 so I'm not sure if 2d vectors are used the same.  If someone could post a sample of how to do this, that would be great.
Title: Trouble with sf::vector2
Post by: P@u1 on November 11, 2011, 09:28:19 am
what is your problem?


Code: [Select]

typedef sf::Vector2<double> Vector2d;

Vector2d vec(1, 5);
//and you are done.
//if you want to change the coords just do
vec.x = 42;
vec.y = 1337;
Title: Trouble with sf::vector2
Post by: Bones on November 11, 2011, 10:38:27 am
Quote from: "P@u1"
what is your problem?


Code: [Select]

typedef sf::Vector2<double> Vector2d;

Vector2d vec(1, 5);
//and you are done.
//if you want to change the coords just do
vec.x = 42;
vec.y = 1337;


I'm getting an error from setting vec:"this declaration has no storage class or type specifier." For some reason vec has no members :/

EDIT:I put it in my main function and it seems to work.
Title: Trouble with sf::vector2
Post by: shruubi on November 12, 2011, 01:34:20 pm
i think you're problem is that the vector class uses a template for it's datatype and you are omitting it.

eg:

Code: [Select]

sf::Vector2<int> vector;


where you put the datatype you wish to use in between the <> characters.
Title: Trouble with sf::vector2
Post by: Nexus on November 12, 2011, 02:16:39 pm
No, his problem is that he wrote statements outside of functions. Maybe he should read the basic chapters of his C++ book again ;)