-
Notifications
You must be signed in to change notification settings - Fork 1
Vector
Used for storing two numbers.
This represents a 2D point or vector in space. This is used throughout the engine in order to store positions and scales of gameObjects.
Note: To apply static operations to vector check out the vecMath class
vector(x = 0, y = 0)
When the vector is instanciated the X and Y can be set as parameters of the constructor. If no paramters are given the vector will to default to vector(0, 0);
float getX()
float getY()
Returns the corresponding component of the vector
void vector.Set(float x, float y);
This will set the X and Y components of the vector based on the parameters passed. Note that the parameters need to be number or else this error will be generated: "value is not a number"
float vector.getByNumber(int index);
Returns either the X or Y of that vector. Where: When index is 0 return X. When index is 1 return Y. If the index is not 1 or 0 an error of "Index out of range" will be thrown
string vector.toString();
Returns the vector as a formatted string for printing. e.g:
new vector(2, 5).toString(); Would return "x: 2 y: 5"
//Create a vector storing and x, y of 3. 2
var foo = new vector(3, 2);
//Foo can be set in two ways:
//Each does the exact same
foo.set(1, 6);
foo = new vector(1, 6);
//The X and Y of foo can be gotten in these ways:
foo.getX(); //Returns 1
foo.getbyNumber(0); //Returns 1
foo.getY(); //Returns 6
foo.getbyNumber(1); //Returns 6
//Changing only one component
//Sets only the Y of foo
foo.set(foo.getX(), 8);
foo.set(4, foo.getY())
foo = new vector(foo.getX(), 8);
foo = new vector(4, foo.getY());
//Printing vectors uses toString
foo = new vector(7, 8);
foo.toString(); //Returns string: 'x: 7 y: 8'
//Finally an example of vector usage.
var foo = new vector(4, 6);
var test foo.set(foo.getX(), 5 * foo.getY()).toString():
//Test yourself. What will the value of test be?
//Answer: 'x: 4 y: 30'