AnimationTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Rendering2D.Tests AnimationTests

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

public class AnimationTests : TestWithMocksOrVisually

The AnimationTests type exposes the following members.

Constructors

  NameDescription
Public methodAnimationTests
Initializes a new instance of the AnimationTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodAdvancingTillLastFrameGivesEvent
Public methodChangeDuration
Public methodCheckAnimatedTime
Public methodCreateAnimatedSprite
Public methodCreateAnimatedSpriteNoImages
Public methodCreateAnimationWithEmptyTextures
Public methodCreateAnimationWithNewTextures
Public methodCreateMaterial
Public methodFramesWillNotAdvanceIfIsPlayingFalse
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Public methodRender2AnimatedSpritesWithDifferentDuration
Public methodRenderAnimatedSprite
Public methodRenderEarthSpriteSheet
Public methodRenderingHiddenAnimationDoesNotThrowException
Public methodResetResetsCurrentFrameAndElapsed
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, ApproveFirstFrameScreenshot]
public void RenderAnimatedSprite()
{
    new Sprite(material, Vector2D.Half);
}
[Test]
public void RenderEarthSpriteSheet()
{
    new Sprite(new Material(ShaderFlags.Position2DTextured, "EarthSpriteSheet"), Vector2D.Half);
}
[Test, ApproveFirstFrameScreenshot]
public void Render2AnimatedSpritesWithDifferentDuration()
{
    new Sprite(material, new Rectangle(0.3f, 0.4f, 0.2f, 0.2f));
    var material2 = new Material(ShaderFlags.Position2DTextured, "ImageAnimation") { Duration = 1 };
    new Sprite(material2, new Rectangle(0.55f, 0.4f, 0.2f, 0.2f));
}
[Test, CloseAfterFirstFrame]
public void CheckAnimatedTime()
{
    var animation = new Sprite(material, Vector2D.Half);
    RunAfterFirstFrame(() =>
    {
        float elapsed = animation.Elapsed;
        var currentFrame = (int)elapsed % 3.0f;
        Assert.AreEqual(currentFrame, animation.CurrentFrame);
    });
}
[Test, CloseAfterFirstFrame]
public void CreateAnimatedSprite()
{
    var images = CreateImages();
    var animation = new Sprite(material, Vector2D.Half);
    Assert.AreEqual(images, animation.Material.Animation.Frames);
    Assert.AreEqual(images[0], animation.Material.DiffuseMap);
    Assert.AreEqual(3, animation.Material.Duration);
}
[Test, CloseAfterFirstFrame]
public void CreateAnimatedSpriteNoImages()
{
    Assert.Throws<ImageAnimation.NoImagesGivenNeedAtLeastOne>(
        () => ContentLoader.Load<ImageAnimation>("ImageAnimationNoImages"));
}
[Test, CloseAfterFirstFrame]
public void ChangeDuration()
{
    material.Duration = 2;
    var animation = new Sprite(material, Vector2D.Half);
    Assert.AreEqual(3, animation.Material.Animation.DefaultDuration);
    Assert.AreEqual(2, animation.Material.Duration);
}
[Test, CloseAfterFirstFrame]
public void ResetResetsCurrentFrameAndElapsed()
{
    var animation = new Sprite(material, Vector2D.Half) { CurrentFrame = 3, Elapsed = 3.0f };
    animation.Reset();
    RunAfterFirstFrame(() =>
    {
        Assert.AreEqual(0, animation.CurrentFrame);
        Assert.AreEqual(0.05f, animation.Elapsed);
    });
}
[Test, ApproveFirstFrameScreenshot]
public void CreateAnimationWithNewTextures()
{
    var imageList = new[]
    {
        CreateImageWithColor(Color.Red), CreateImageWithColor(Color.CornflowerBlue),
        CreateImageWithColor(Color.Purple)
    };
    var newMaterial = new ImageAnimation(imageList, 3).CreateMaterial(
        ContentLoader.Create<Shader>(new ShaderCreationData(ShaderFlags.Position2DTextured)));
    new Sprite(newMaterial, new Rectangle(0.25f, 0.25f, 0.5f, 0.5f));
}
[Test, CloseAfterFirstFrame]
public void CreateAnimationWithEmptyTextures()
{
    var emptyImageList = new Image[0];
    Assert.Throws<ImageAnimation.NoImagesGivenNeedAtLeastOne>(
        () => new ImageAnimation(emptyImageList, 3));
}
[Test, CloseAfterFirstFrame]
public void RenderingHiddenAnimationDoesNotThrowException()
{
    new Sprite(material, Rectangle.One) { IsVisible = false };
    Assert.DoesNotThrow(() => AdvanceTimeAndUpdateEntities());
}
[Test]
public void AdvancingTillLastFrameGivesEvent()
{
    var animation = new Sprite(material, Vector2D.Half);
    bool endReached = false;
    animation.AnimationEnded += () => { endReached = true; };
    AdvanceTimeAndUpdateEntities(animation.Material.Duration + 0.1f);
    Assert.IsTrue(endReached, animation.ToString());
}
[Test, CloseAfterFirstFrame]
public void FramesWillNotAdvanceIfIsPlayingFalse()
{
    var animation = new Sprite(material, Vector2D.Half);
    bool endReached = false;
    animation.AnimationEnded += () => { endReached = true; };
    animation.IsPlaying = false;
    AdvanceTimeAndUpdateEntities(animation.Material.Duration);
    Assert.IsFalse(endReached);
}
See Also