/// <summary> /// Handles adding a new component to this GameScreen. /// </summary> /// <param name="component">The component to add to this GameScreen.</param> public void AddComponent(Component component) { if (components.Contains(component)) return; components.Add(component); // We want to track what screen the component is associationed with, i.e. the parent. component.Parent = this; component.LoadComponent(); PutComponentInOrder(component); }
/// <summary> /// We want to be able to render some components on top of or behind other components, so a DrawOrder variable has been provided. This method sorts /// components by that DrawOrder. /// </summary> /// <param name="component"></param> public void PutComponentInOrder(Component component) { if (!components.Contains(component)) return; components.Remove(component); int i; for (i = 0; i < components.Count; i++) { if (components[i].DrawOrder >= component.DrawOrder) break; } components.Insert(i, component); }
/// <summary> /// Handles removal of components on the current screen by the component object. /// </summary> /// <param name="component">The component to remove from the screen.</param> public void RemoveComponent(Component component) { if (component == null || !components.Contains(component)) return; components.Remove(component); component.Parent = null; }