time and space

time and space

  • 1.4k
  • 31
  • 57.1k

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)