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
Afficher le fichier Open project: fmotagarcia/sparrow-sharp Class Usage Examples

Méthodes publiques

Méthode 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 méthode

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

AddChild() public méthode

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

BoundsInSpace() public méthode

public BoundsInSpace ( DisplayObject targetSpace ) : Rectangle
targetSpace DisplayObject
Résultat Sparrow.Geom.Rectangle

ContainsChild() public méthode

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

GetChild() public méthode

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

GetChild() public méthode

Returns a child object at a certain index.
public GetChild ( int index ) : DisplayObject
index int
Résultat DisplayObject

GetChild() public méthode

Returns a child object at a certain index.
public GetChild ( uint index ) : DisplayObject
index uint
Résultat DisplayObject

GetChildIndex() public méthode

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
Résultat int

HitTestPoint() public méthode

public HitTestPoint ( Point localPoint ) : DisplayObject
localPoint Point
Résultat DisplayObject

RemoveAllChildren() public méthode

Removes all children from the container.
public RemoveAllChildren ( ) : void
Résultat void

RemoveChild() public méthode

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

RemoveChildAt() public méthode

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

Render() public méthode

public Render ( RenderSupport support ) : void
support Sparrow.Core.RenderSupport
Résultat void

SetChildIndex() public méthode

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
Résultat void

SortChildren() public méthode

Sorts the children using the given IComparer.
public SortChildren ( IComparer comparator ) : void
comparator IComparer
Résultat void

SwapChild() public méthode

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

SwapChildrenAt() public méthode

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