XNA framework for .net has a really useful Object called vector2 that represents a 2d vector..You can multiply them by ints, floats and other Vector 2s
Eg.
Vector2 bloo = new Vector2(5, 5);
bloo *= 5;
bloo *= someotherVector2;
The only thing is that the X,Y information is stored as floats and in a lot of cases I want to simply store 2d info, or 2d coordinates as ints.
I’d like to make my own struct for this..
Heres what i have..
internal struct Coord
{
public int X { get; private set; }
public int Y { get; private set; }
public Coord(int x,int y)
{
X = x;
Y = y;
}
}
My question is how do I make it so my Coord struct can be multipled by ints or other Coords using * (Not a “Multiply” function call)
You can use operator overloading:
Just put the method into the
Coordstruct. You can do this with many operators like+,-,/etc… and also with different parameters.