I have a project in which I'm trying to remove the "collision box" (Rectangle class) of one of my enemy. My game logic basically is:
foreach (Enemy e in Enemy.enemiesOnScreen) {
if (e._isDead) {
e._collisionBox = new Rectangle(0, 0, 0, 0);
}
else {
e.Update(gameTime);
}
}
What I wrote works perfectly, but wouldn't that be subject to memory overflow (for a much higher number of instances) or bad optimization in a real game project ?
xna
but have you triede._collisionBox = null;
or something similar? \$\endgroup\$null
isn't accepted, then it sounds like yourRectangle
type is astruct
. Assigning anew
instance of a struct to an existing field does not cause memory allocation, as discussed previously here \$\endgroup\$new
instance of a struct doesn't allocate memory anywhere else since the struct already allocates storage memory for its values. \$\endgroup\$