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 ?
xnabut have you triede._collisionBox = null;or something similar? \$\endgroup\$nullisn't accepted, then it sounds like yourRectangletype is astruct. Assigning anewinstance of a struct to an existing field does not cause memory allocation, as discussed previously here \$\endgroup\$newinstance of a struct doesn't allocate memory anywhere else since the struct already allocates storage memory for its values. \$\endgroup\$