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

Author Topic: Trouble with sf::vector2  (Read 2842 times)

0 Members and 1 Guest are viewing this topic.

Bones

  • Newbie
  • *
  • Posts: 24
    • View Profile
Trouble with sf::vector2
« 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.

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
Trouble with sf::vector2
« Reply #1 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;

Bones

  • Newbie
  • *
  • Posts: 24
    • View Profile
Trouble with sf::vector2
« Reply #2 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.

shruubi

  • Newbie
  • *
  • Posts: 3
    • View Profile
Trouble with sf::vector2
« Reply #3 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Trouble with sf::vector2
« Reply #4 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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything