/// <summary> /// Add all the objects in ObjectsToAdd to ActiveObjects, then update ActiveObjects before deleting objects in ObjectsToRemove /// </summary> /// <param name="elapsedGameTime">The seconds that have elapsed since the last update loop</param> public override void Update(float elapsedGameTime) { // Always call the super class' function - it will deal with whether it should run it itself base.Update(elapsedGameTime); // Add the objects and then clear the list - it is only a temporary holder ActiveObjects.AddRange(ObjectsToAdd); ObjectsToAdd.Clear(); // Loop through the active object foreach (T obj in ActiveObjects) { if (obj.ShouldUpdate) { // Update the object obj.Update(elapsedGameTime); } } // Remove all the objects that are no longer alive ActiveObjects.RemoveAll(x => x.IsAlive == false); // Remove all the objects we have marked to remove foreach (T obj in ObjectsToRemove) { ActiveObjects.Remove(obj); } ObjectsToRemove.Clear(); // Clear the list - it is only a temporary holder }