4
Answers

Boxing/unboxing problem

Ask a question
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)