public void ProcessAnimations_ShouldNotAdvancePositionOfSpriteAnimationComponent_WhenThereIsNoCurrentAnimation() { // Arrange var builder = new AnimationSceneBuilder(); var spriteAnimationComponent = builder.AddSpriteAnimationComponent(); spriteAnimationComponent.AddAnimation("anim", CreateAnimation(TimeSpan.FromMilliseconds(20))); var scene = builder.Build(); // Assume Assume.That(spriteAnimationComponent.Position, Is.Zero); // Act _animationSystem.ProcessAnimations(scene, new GameTime(TimeSpan.FromMilliseconds(10))); // Assert Assert.That(spriteAnimationComponent.Position, Is.Zero); }
public void ProcessAnimations_ShouldAdvancePositionOfSpriteAnimationComponent(int animationDuration, int deltaTime, double playbackSpeed, double initialPosition, double expectedPosition) { // Arrange var builder = new AnimationSceneBuilder(); var spriteAnimationComponent = builder.AddSpriteAnimationComponent(); spriteAnimationComponent.AddAnimation("anim", CreateAnimation(TimeSpan.FromMilliseconds(animationDuration))); var scene = builder.Build(); spriteAnimationComponent.PlayAnimation("anim"); spriteAnimationComponent.PlaybackSpeed = playbackSpeed; spriteAnimationComponent.Position = initialPosition; // Act _animationSystem.ProcessAnimations(scene, new GameTime(TimeSpan.FromMilliseconds(deltaTime))); // Assert Assert.That(spriteAnimationComponent.Position, Is.EqualTo(expectedPosition)); }
ProcessAnimations_ShouldAdvancePositionOfSpriteAnimationComponentToTheEndAndContinuePlayingFromBeginningAndNotifyWithEvent_WhenAnimationPlayedInLoop( int deltaTime) { // Arrange var builder = new AnimationSceneBuilder(); var spriteAnimationComponent = builder.AddSpriteAnimationComponent(); var spriteAnimation = CreateAnimation(TimeSpan.FromMilliseconds(100)); spriteAnimationComponent.AddAnimation("anim", spriteAnimation); var scene = builder.Build(); spriteAnimationComponent.PlayAnimation("anim"); spriteAnimationComponent.Position = 0.8; spriteAnimationComponent.PlayInLoop = true; object?eventSender = null; SpriteAnimationCompletedEventArgs?eventArgs = null; spriteAnimationComponent.AnimationCompleted += (sender, args) => { eventSender = sender; eventArgs = args; }; // Act _animationSystem.ProcessAnimations(scene, new GameTime(TimeSpan.FromMilliseconds(deltaTime))); // Assert Assert.That(spriteAnimationComponent.Position, Is.EqualTo(0.3).Within(1e-15)); Assert.That(spriteAnimationComponent.IsPlaying, Is.True); Assert.That(eventSender, Is.Not.Null, "Event sender is null."); Assert.That(eventSender, Is.EqualTo(spriteAnimationComponent)); Assert.That(eventArgs, Is.Not.Null, "Event args are null."); Debug.Assert(eventArgs != null, nameof(eventArgs) + " != null"); Assert.That(eventArgs.AnimationName, Is.EqualTo("anim")); Assert.That(eventArgs.Animation, Is.EqualTo(spriteAnimation)); }
public void ProcessAnimations_ShouldInvokeAnimationCompletedAfterAdvancingPosition_WhenAnimationEnded() { // Arrange var builder = new AnimationSceneBuilder(); var spriteAnimationComponent = builder.AddSpriteAnimationComponent(); var spriteAnimation = CreateAnimation(TimeSpan.FromMilliseconds(100)); spriteAnimationComponent.AddAnimation("anim", spriteAnimation); var scene = builder.Build(); spriteAnimationComponent.PlayAnimation("anim"); spriteAnimationComponent.Position = 0.8; spriteAnimationComponent.AnimationCompleted += (sender, args) => { spriteAnimationComponent.PlayAnimation("anim"); }; // Act _animationSystem.ProcessAnimations(scene, new GameTime(TimeSpan.FromMilliseconds(50))); // Assert Assert.That(spriteAnimationComponent.Position, Is.EqualTo(0.0)); Assert.That(spriteAnimationComponent.IsPlaying, Is.True); }
public void ProcessAnimations_ShouldAdvancePositionOfSpriteAnimationComponentToTheEndAndStopAnimationAndNotifyWithEvent() { // Arrange var builder = new AnimationSceneBuilder(); var spriteAnimationComponent = builder.AddSpriteAnimationComponent(); var spriteAnimation = CreateAnimation(TimeSpan.FromMilliseconds(100)); spriteAnimationComponent.AddAnimation("anim", spriteAnimation); var scene = builder.Build(); spriteAnimationComponent.PlayAnimation("anim"); spriteAnimationComponent.Position = 0.8; object?eventSender = null; SpriteAnimationCompletedEventArgs?eventArgs = null; spriteAnimationComponent.AnimationCompleted += (sender, args) => { eventSender = sender; eventArgs = args; }; // Act _animationSystem.ProcessAnimations(scene, new GameTime(TimeSpan.FromMilliseconds(50))); // Assert Assert.That(spriteAnimationComponent.Position, Is.EqualTo(1.0)); Assert.That(spriteAnimationComponent.IsPlaying, Is.False); Assert.That(eventSender, Is.Not.Null, "Event sender is null."); Assert.That(eventSender, Is.EqualTo(spriteAnimationComponent)); Assert.That(eventArgs, Is.Not.Null, "Event args are null."); Debug.Assert(eventArgs != null, nameof(eventArgs) + " != null"); Assert.That(eventArgs.AnimationName, Is.EqualTo("anim")); Assert.That(eventArgs.Animation, Is.EqualTo(spriteAnimation)); }