I have a question about XNA which I am new too and could not find a clear answer for in the documentation after searching google.
Question 1:
If I do this:
Rectangle afterMoveRect = collisionRectangle;
afterMoveRect.Offset((int)moveAmount.X, (int)moveAmount.Y);
Did I now:
A. refference collisionRectangle with another name and afterwards moved collisionRectangle
or
B. Created a duplicate copy of collisionRectangle and only moved the copy.
Second question:
If I do this:
Matrix transform = localTransform;
transform = transform * otherTransform;
Did I create a copy of localTransform and mulitplied the copy or did I reference localTransform and multiplied it through another identifier?
The question for both is the same, did I change the original (perhaps unintentionally)
Question 3:
How do you know if you changed the original or not? How do you know if you reference the original with a new name (like in Java) or create a deep copy of the other object when using the assignment operator?
Depends entirely if
RectangleorMatrixis astructor aclass.If it is a
struct(a value type), it will be copied, you are working on a different instance. If it is aclass(a reference type) it will be referenced, you are working on the same object.According to the msdn, both Rectangle and Matrix are structs, so you are working on copies.