/// <summary> /// Play the sprite animation defined by the provided sequence of indices. /// </summary> /// <param name="spriteComponent">The sprite component containing the animation</param> /// <param name="indices">The sequence of indices defining the sprite animation</param> /// <param name="repeatMode">The value indicating how to loop the animation</param> /// <param name="framesPerSeconds">The animation speed in frames per second. 0 to use the sprite animation system default speed.</param> /// <param name="clearQueuedAnimations">Indicate if queued animation should be cleared</param> public void Play(SpriteComponent spriteComponent, int[] indices, AnimationRepeatMode repeatMode, float framesPerSeconds = 0, bool clearQueuedAnimations = true) { if (spriteComponent == null) { return; } var animationInfo = new SpriteComponent.AnimationInfo { ShouldLoop = repeatMode == AnimationRepeatMode.LoopInfinite, SpriteIndices = SpriteComponent.GetNewSpriteIndicesList(), FramePerSeconds = framesPerSeconds > 0 ? framesPerSeconds : DefaultFramesPerSecond, }; foreach (var i in indices) { animationInfo.SpriteIndices.Add(i); } spriteComponent.RecycleFirstAnimation(); spriteComponent.Animations.Enqueue(animationInfo); var queuedAnimationsCount = spriteComponent.Animations.Count - 1; for (int i = 0; i < queuedAnimationsCount; i++) { var queuedAnimation = spriteComponent.Animations.Dequeue(); if (!clearQueuedAnimations) { spriteComponent.Animations.Enqueue(queuedAnimation); } } playingSprites.Add(spriteComponent); spriteComponent.ElapsedTime = 0; spriteComponent.CurrentIndexIndex = 0; spriteComponent.IsPaused = false; }