示例#1
0
 public bool AddChild(DisplayObject obj)
 {
     if (obj.parent != null)
     {
         return false;
     }
     children.Add(obj);
     obj.parent = this;
     obj.DispatchEvent(new Event(Event.ADDED_TO_STAGE));
     obj.GlobalTransform = transformMatrix;
     return true;
 }
示例#2
0
        /// <summary>
        /// Checks if object intersects with other 
        /// </summary>
        /// <param name="obj">Displayobject to check intersection with</param>
        /// <returns>true, if objects intersects, false otherwise</returns>
        public virtual bool HitTestObject(DisplayObject obj)
        {
            throw new NotImplementedException("A HitTestObject is not implemented yet");

            var bounds1 = GetBounds();
            var bounds2 = obj.GetBounds();
            // TODO: Coordinates should be all transformed to global!
            // Global first body
            var topLeft1_g = this.LocalToGlobal(new Vector2(bounds1.X, bounds1.Y));
            var botRight1_g = this.LocalToGlobal(new Vector2(bounds1.Z, bounds1.W));
            // Global second body
            var topLeft2_g = obj.LocalToGlobal(new Vector2(bounds2.X, bounds2.Y));
            var botRight2_g = obj.LocalToGlobal(new Vector2(bounds2.Z, bounds2.W));
            // Setup boundig boxes
            BoundingBox bb1 = new BoundingBox(new Vector3(topLeft1_g, 0), new Vector3(botRight1_g, 0));
            BoundingBox bb2 = new BoundingBox(new Vector3(topLeft2_g, 0), new Vector3(botRight2_g, 0));

            return bb1.Intersects(bb2);
        }
示例#3
0
 public bool AddChildAt(DisplayObject obj, int index)
 {
     if (obj.parent != null)
     {
         return false;
     }
     // Вставка перед объектом с индексом index
     children.Insert(index + 1, obj);
     obj.parent = this;
     obj.DispatchEvent(new Event(Event.ADDED_TO_STAGE));
     obj.GlobalTransform = transformMatrix;
     return true;
 }
示例#4
0
 public bool RemoveChild(DisplayObject obj)
 {
     if (!children.Remove(obj))
     {
         return false;
     }
     obj.DispatchEvent(new Event(Event.REMOVED_FROM_STAGE));
     obj.parent = null;
     obj.stage = null;
     return true;
 }
示例#5
0
 public int GetChildIndex(DisplayObject obj)
 {
     return children.IndexOf(obj);
 }