C# Class Sparrow.Display.DisplayObjectContainer

A DisplayObjectContainer represents a collection of display objects. It is the base class of all display objects that act as a container for other objects. By maintaining an ordered list of children, it defines the back-to-front positioning of the children within the display tree. A container does not have size in itself. The width and height properties represent the extents of its children. Changing those properties will scale all children accordingly. As this is an abstract class, you can't instantiate it directly, but have to use a subclass instead. The most lightweight container class is Sprite. **Adding and removing children** The class defines methods that allow you to add or remove children. When you add a child, it will be added at the foremost position, possibly occluding a child that was added before. You can access the children via an index. The first child will have index 0, the second child index 1, etc. Adding and removing objects from a container triggers events. - 'Added': the object was added to a DisplayObjectContainer. - 'AddedToStage': the object was added to a DisplayObjectContainer that is connected to the stage. - 'Removed': the object was removed from a DisplayObjectContainer. - 'RemovedFromStage': the object was removed from a DisplayObjectContainer that is connected to the stage. Especially the AddedToStage event is very helpful, as it allows you to automatically execute some logic (e.g. start an animation) when an object is rendered the first time. **Sorting children** The 'sortChildren' method allows you to sort the children of a container by a custom criteria. Below is an example how to depth-sort children by their y-coordinate; this will put objects that are lower on the screen in front of those higher on the screen. public class CompareExample : IComparator { public int Compare(DisplayObject child1, DisplayObject child2) { if (child1.Y < child2.Y) return -1; else if (child1.Y > child2.Y) return 1; else return 0; } }
Inheritance: DisplayObject
Exibir arquivo Open project: fmotagarcia/sparrow-sharp Class Usage Examples

Public Methods

Method Description
AddChild ( DisplayObject child ) : void

Adds a child to the container. It will be at the topmost position.

AddChild ( DisplayObject child, int index ) : void

Adds a child to the container at a certain index.

BoundsInSpace ( DisplayObject targetSpace ) : Rectangle
ContainsChild ( DisplayObject child ) : bool

Determines if a certain object is a child of this container (recursively).

GetChild ( String name ) : DisplayObject

Returns a child object with a certain name (non-recursively).

GetChild ( int index ) : DisplayObject

Returns a child object at a certain index.

GetChild ( uint index ) : DisplayObject

Returns a child object at a certain index.

GetChildIndex ( DisplayObject child ) : int

Returns the index of a child within the container. Returns -1 if the child is not within this container

HitTestPoint ( Point localPoint ) : DisplayObject
RemoveAllChildren ( ) : void

Removes all children from the container.

RemoveChild ( DisplayObject child ) : void

Removes a child from the container. If the object is not a child, nothing happens.

RemoveChildAt ( int index ) : void

Removes a child at a certain index. Children above the child will move down.

Render ( RenderSupport support ) : void
SetChildIndex ( DisplayObject child, int index ) : void

Moves a child to a certain index. Children at and after the replaced position move up. throws ArgumentException if the child is not found

SortChildren ( IComparer comparator ) : void

Sorts the children using the given IComparer.

SwapChild ( DisplayObject child1, DisplayObject child2 ) : void

Swaps the indexes of two children.

SwapChildrenAt ( int index1, int index2 ) : void

Swaps the indexes of two children.

Method Details

AddChild() public method

Adds a child to the container. It will be at the topmost position.
public AddChild ( DisplayObject child ) : void
child DisplayObject
return void

AddChild() public method

Adds a child to the container at a certain index.
public AddChild ( DisplayObject child, int index ) : void
child DisplayObject
index int
return void

BoundsInSpace() public method

public BoundsInSpace ( DisplayObject targetSpace ) : Rectangle
targetSpace DisplayObject
return Sparrow.Geom.Rectangle

ContainsChild() public method

Determines if a certain object is a child of this container (recursively).
public ContainsChild ( DisplayObject child ) : bool
child DisplayObject
return bool

GetChild() public method

Returns a child object with a certain name (non-recursively).
public GetChild ( String name ) : DisplayObject
name String
return DisplayObject

GetChild() public method

Returns a child object at a certain index.
public GetChild ( int index ) : DisplayObject
index int
return DisplayObject

GetChild() public method

Returns a child object at a certain index.
public GetChild ( uint index ) : DisplayObject
index uint
return DisplayObject

GetChildIndex() public method

Returns the index of a child within the container. Returns -1 if the child is not within this container
public GetChildIndex ( DisplayObject child ) : int
child DisplayObject
return int

HitTestPoint() public method

public HitTestPoint ( Point localPoint ) : DisplayObject
localPoint Point
return DisplayObject

RemoveAllChildren() public method

Removes all children from the container.
public RemoveAllChildren ( ) : void
return void

RemoveChild() public method

Removes a child from the container. If the object is not a child, nothing happens.
public RemoveChild ( DisplayObject child ) : void
child DisplayObject
return void

RemoveChildAt() public method

Removes a child at a certain index. Children above the child will move down.
public RemoveChildAt ( int index ) : void
index int
return void

Render() public method

public Render ( RenderSupport support ) : void
support Sparrow.Core.RenderSupport
return void

SetChildIndex() public method

Moves a child to a certain index. Children at and after the replaced position move up. throws ArgumentException if the child is not found
public SetChildIndex ( DisplayObject child, int index ) : void
child DisplayObject
index int
return void

SortChildren() public method

Sorts the children using the given IComparer.
public SortChildren ( IComparer comparator ) : void
comparator IComparer
return void

SwapChild() public method

Swaps the indexes of two children.
public SwapChild ( DisplayObject child1, DisplayObject child2 ) : void
child1 DisplayObject
child2 DisplayObject
return void

SwapChildrenAt() public method

Swaps the indexes of two children.
public SwapChildrenAt ( int index1, int index2 ) : void
index1 int
index2 int
return void