HierarchyEntity2D Parent Property Delta Engine Documentation

Namespace: DeltaEngine.Rendering2D
Assembly: DeltaEngine.Rendering2D (in DeltaEngine.Rendering2D.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public HierarchyObject2D Parent { get; }

Property Value

Type: HierarchyObject2D

Implements

HierarchyObject2D Parent
Remarks

Tests: DeltaEngine.Rendering2D.Tests.HierarchyEntity2DTests
Examples

4 unit tests call DeltaEngine.Rendering2D.HierarchyEntity2D.Parent
[Test]
public void PositionOfChildUpdatedRelativeToParentOnParentPositionChange()
{
    var parentEntity = new MockHierarchyEntity2D(Rectangle.FromCenter(Vector2D.Half, Size.Zero));
    var childEntity = new MockHierarchyEntity2D(Rectangle.FromCenter(0.4f, 0.4f, 0.1f, 0.1f));
    var grandChildEntity =
        new MockHierarchyEntity2D(Rectangle.FromCenter(new Vector2D(0.2f, 0.0f), Size.Zero));
    parentEntity.Add(childEntity);
    childEntity.Add(grandChildEntity);
    Assert.AreEqual(new Vector2D(0.4f, 0.4f), childEntity.Center);
    Assert.AreEqual(new Vector2D(0.2f, 0.0f), grandChildEntity.Center);
    parentEntity.Center += new Vector2D(0.1f, 0.1f);
    Assert.IsTrue(new Vector2D(0.5f, 0.5f).IsNearlyEqual(childEntity.Center),
        childEntity.Center.ToString());
    Assert.IsTrue(new Vector2D(-0.1f, -0.1f).IsNearlyEqual(childEntity.RelativePosition),
        childEntity.RelativePosition.ToString());
    Assert.IsTrue(new Vector2D(0.3f, 0.1f).IsNearlyEqual(grandChildEntity.Center),
        grandChildEntity.Center.ToString());
    Assert.IsTrue(new Vector2D(-0.2f, -0.4f).IsNearlyEqual(grandChildEntity.RelativePosition),
        grandChildEntity.RelativePosition.ToString());
}
[Test]
public void BuildHierarchyOfDifferentEntities()
{
    var parentEntity = new MockHierarchyEntity2D();
    var entityGivenPosition = new MockHierarchyEntity2D(new Vector2D(0.3f, 0.4f));
    var entityGivenRect = new MockHierarchyEntity2D(new Rectangle(0.1f, 0.0f, 0.5f, 0.4f), 20);
    parentEntity.Add(entityGivenPosition);
    parentEntity.Add(entityGivenRect);
    Assert.AreEqual(parentEntity, entityGivenPosition.Parent);
    Assert.AreEqual(new Vector2D(0.3f, 0.4f), entityGivenPosition.RelativePosition);
    Assert.AreEqual(parentEntity, entityGivenRect.Parent);
    Assert.AreEqual(20, entityGivenRect.RelativeRotation);
}
[Test]
public void SettingLocalWithoutParentSetsGlobal()
{
    var entity = new MockHierarchyEntity2D();
    var setPosition = new Vector2D(0.2f,0.5f);
    const float SetRotation = 30.0f;
    entity.RelativePosition = setPosition;
    entity.RelativeRotation = SetRotation;
    Assert.AreEqual(setPosition, entity.Center);
    Assert.AreEqual(SetRotation, entity.Rotation);
}
See Also