4
Answers

Boxing/unboxing problem

time and space

time and space

12y
1.8k
1
The following code snippet crops up quite often in my code where collision rectangles need to be calculated:

bullet.collisionRect.X = (int)bullet.position.X;
bullet.collisionRect.Y = (int)bullet.position.Y;

Is there any way round the unboxing/cast?  The collision rects are XNA Rectangles, position X, Y are floats (stored in a Vector2).
Answers (4)