Beispiel #1
0
 protected void AddComponent(Component component)
 {
     Parent.AddComponent(component);
 }
Beispiel #2
0
 /// <summary>
 /// Remove a component from Gamescreen
 /// </summary>
 /// <param name="Component">The component instance to remove</param>
 public void RemoveComponent(Component Component)
 {
     if (Component != null && components.Contains(Component))
     {
         Component.OnRemove();
         components.Remove(Component);
         Component.Parent = null;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Add a new component to the gamescreen.
 /// </summary>
 /// <param name="Component">The component to add</param>
 /// <param name="Active">Can the component update?</param>
 /// <param name="Visible">Can the component draw?</param>
 public void AddComponent(Component Component, bool Active, bool Visible)
 {
     if (!components.Contains(Component))
     {
         components.Add(Component);
         Component.Parent = this;
         Component.ParentEngine = this.engine;
         Component.Active = Active;
         Component.Visible = Visible;
         Component.LoadComponent();
         PutComponentsInOrder(Component);
     }
 }
Beispiel #4
0
        // The components are stored in their draw order, so it is easy to loop
        // through them and draw them in the correct order without having to sort
        // them every time they are drawn
        /// <summary>
        /// Sorts the Gamescreen's by their draw order.
        /// </summary>
        /// <param name="component">The component to insert</param>
        public void PutComponentsInOrder(Component component)
        {
            if (components.Contains(component))
            {
                components.Remove(component);

                int i = 0;

                // TODO The component sorting uses a linear search, consider implementing a better sorting algorithm

                // Iterate through the components in order until we find one with
                // a higher or equal draw order, and insert the component at that
                // position.
                for (i = 0; i < components.Count; i++)
                    if (components[i].DrawOrder >= component.DrawOrder)
                        break;

                components.Insert(i, component);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Add a new component to the Gamescreen.
 /// </summary>
 /// <param name="Component">The component to add</param>
 public void AddComponent(Component Component)
 {
     if (!components.Contains(Component))
     {
         Component.Parent = this;
         Component.ParentEngine = this.engine;
         Component.LoadComponent();
         PutComponentsInOrder(Component);
         components.Add(Component);
     }
 }