time and space

time and space

  • 1.6k
  • 31
  • 55.8k

Boxing/unboxing problem

Apr 9 2012 2:10 PM
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)