Beispiel #1
0
        public void Constructor_ThrowsArgumentNullException_OnNullFrame()
        {
            Frame firstFrame = new Frame(region, 0.1);
            Frame secondFrame = null;
            var frames = new Frame[] { firstFrame, secondFrame };
            Action construct = () => new Animation(frames);

            construct.ShouldThrow<ArgumentNullException>().ParamName.ShouldBe("frame");
        }
Beispiel #2
0
        public void Constructor_ThrowsArgumentException_OnEmptyFrames()
        {
            var frames = new Frame[] { };
            Action construct = () => new Animation(frames);

            construct.ShouldThrow<ArgumentException>().Message.ShouldContain(
                "An animation requires at least one frame. Zero found"
            );
        }
Beispiel #3
0
        public void Constructor_CorrectlyInitialises_Instance()
        {
            var region = new TextureRegion(0, 0, 50, 50);
            var frame = new Frame(region, 0.1);

            frame.ShouldSatisfyAllConditions(
                () => frame.TextureRegion.ShouldBe(region),
                () => frame.Duration.ShouldBe(0.1)
            );
        }
Beispiel #4
0
        public void Update(double delta)
        {
            totalElapsedTime += delta;
            // get the point in the animation at which the current frame ends
            double currentAnimationPoint = frames.Take(currentFrameIndex + 1)
                                                 .Sum(f => f.Duration);

            if (totalElapsedTime >= currentAnimationPoint && currentFrameIndex < frames.Length - 1)
            {
                currentFrameIndex++;
                currentFrame = frames[currentFrameIndex];
            }
            if (totalElapsedTime >= totalDuration && loop)
            {
                Reset();
            }
        }
Beispiel #5
0
 public Animation(bool loop, params Frame[] frames)
 {
     frames.ThrowIfNull(nameof(frames));
     if (frames.Length <= 0)
     {
         throw new ArgumentException(
             "An animation requires at least one frame. Zero found"
         );
     }
     foreach (var frame in frames)
     {
         frame.ThrowIfNull(nameof(frame));
     }
     this.frames = frames;
     this.currentFrame = frames[0];
     this.totalDuration = frames.Sum(f => f.Duration);
     this.loop = loop;
 }
Beispiel #6
0
 public void Reset()
 {
     totalElapsedTime = 0;
     currentFrameIndex = 0;
     currentFrame = frames[currentFrameIndex];
 }