public void TestCompositeWithTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var definition = spriteSheet.AddSpriteDefinition("toto", source, origin);
            var transform = new SpriteTransform(translation: new Vector(43, -27), rotation: -1.2f, scale: 5.0f, color: Color.Yellow);
            var template = spriteSheet.AddSpriteCompositeTemplate("tata")
                .AddTemplate(definition, transform);

            var expectedSprite = new Sprite(spriteSheet, "toto")
            {
                Position = new Vector(43, -27),
                Rotation = -1.2f,
                Scale = 5.0f,
                Color = Color.Yellow
            };

            var expected = new SpriteComposite("tata", new[] { expectedSprite });

            // ACT
            var actual = (SpriteComposite)template.CreateInstance();

            // ASSERT
            AssertSprite.CompositeEqual(expected, actual);
        }
        public void TestAnimationWithTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);
            var transform1 = new SpriteTransform(translation: new Vector(4, -5), rotation: 2.4f, scale: 1.5f, color: Color.Blue);
            var transform2 = new SpriteTransform(translation: new Vector(-6, 3), rotation: -1.2f, scale: 3.0f, color: Color.Red);

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var definition1 = spriteSheet.AddSpriteDefinition("toto1", source, origin);
            var definition2 = spriteSheet.AddSpriteDefinition("toto2", source, origin);
            var template = spriteSheet.AddSpriteAnimationTemplate("tata")
                .AddFrame(definition1, 1.0f, transform1)
                .AddFrame(definition2, 2.5f, transform2);

            var expectedSprite1 = new Sprite(spriteSheet, "toto1");
            var expectedSprite2 = new Sprite(spriteSheet, "toto2");
            var expected = new SpriteAnimation("tata", new[]
            {
                new SpriteAnimationFrame(expectedSprite1, 1.0f, transform1),
                new SpriteAnimationFrame(expectedSprite2, 2.5f, transform2)
            });

            // ACT
            var actual = (SpriteAnimation)template.CreateInstance();

            // ASSERT
            AssertSprite.AnimationEqual(expected, actual);
        }
        public void TestIdentityColor()
        {
            var transform = new SpriteTransform();

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(255, final.Color.R);
            Assert.AreEqual(255, final.Color.G);
            Assert.AreEqual(255, final.Color.B);
            Assert.AreEqual(255, final.Color.A);
        }
        public SpriteCompositeTemplate AddTemplate(SpriteTransform transform, ISpriteTemplate template)
        {
            var def = new TemplateDefinition
            {
                Template = template,
                Transform = transform
            };

            this.templateDefinitions.Add(def);
            return this;
        }
        public void TestColorNoComposition()
        {
            var transform = new SpriteTransform(color: new Color(100, 120, 140, 160));

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(100, final.Color.R);
            Assert.AreEqual(120, final.Color.G);
            Assert.AreEqual(140, final.Color.B);
            Assert.AreEqual(160, final.Color.A);
        }
        public void TestColorWithSimpleComposition()
        {
            var transform = new SpriteTransform(color: new Color(128, 192, 64, 32));
            var transform2 = new SpriteTransform(transform, color: new Color(255, 255, 255, 255));

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(128, final.Color.R);
            Assert.AreEqual(192, final.Color.G);
            Assert.AreEqual(64, final.Color.B);
            Assert.AreEqual(32, final.Color.A);
        }
Ejemplo n.º 7
0
        public override int Draw(IDrawContext drawContext, Transform transform)
        {
            if (this.currentFrame != null && this.IsVisible)
            {
                var newTransform = new SpriteTransform(transform, this.Position, this.Rotation, this.Scale, this.Color);

                if (this.currentFrame.Transform != null)
                    newTransform = new SpriteTransform(newTransform, this.currentFrame.Transform);

                return this.currentFrame.FrameSprite.Draw(drawContext, newTransform);
            }

            return 1;
        }
Ejemplo n.º 8
0
        public override int Draw(IDrawContext drawContext, Transform transform)
        {
            this.SetSampler(drawContext);

            this.drawnElementsLastFrame = 0;

            if (this.CameraMode == CameraMode.Follow)
            {
                transform = new SpriteTransform(transform, scale: drawContext.Camera.ZoomFactor,
                    translation: drawContext.Camera.GetSceneTranslationVector(this.ParallaxScrollingVector));
            }

            transform = new SpriteTransform(transform, this.Offset);

            foreach (var sprite in this.Sprites.Where(s => s.IsVisible))
            {
                this.drawnElementsLastFrame += sprite.Draw(drawContext, transform);
            }

            return this.drawnElementsLastFrame;
        }
Ejemplo n.º 9
0
 public SpriteTransform(SpriteTransform innerTransform, SpriteTransform otherTransform)
     : base(innerTransform, otherTransform.Translation, otherTransform.Rotation, otherTransform.Scale)
 {
     this.Color = innerTransform.Color.Multiply(otherTransform.Color);
 }
        public void TestScaleWithComplexComposition()
        {
            var transform1 = new SpriteTransform(scale: 0.4f);
            var transform2 = new SpriteTransform(transform1, scale: 8.0f);

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(3.2f, final.Scale);
        }
        public void TestScaleWithSimpleComposition()
        {
            var transform1 = new SpriteTransform(scale: 2.4f);
            var transform2 = new SpriteTransform(transform1);

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(2.4f, final.Scale);
        }
        public void TestTranslationIdentityComposition()
        {
            var transform = new SpriteTransform(new SpriteTransform(new SpriteTransform()));

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(Vector.Zero, final.Translation);
        }
Ejemplo n.º 13
0
        public void TestSpriteDrawWithScaleAndTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);
            var transform = new SpriteTransform(scale: 0.25f);

            var expected = CreateDrawImageParams(source, origin,
                destination: new Rectangle(0, 0, 40, 40));

            // ARRANGE
            var sprite = CreateSprite(source, origin);
            sprite.Scale = 8.0f;

            DrawImageParams actual = null;
            var drawContext = CreateDrawContextMock(p => actual = p);

            // ACT
            sprite.Draw(drawContext.Object, transform);

            // ASSERT
            drawContext.VerifyAll();
            AssertDrawImageParamsAreEquals(expected, actual);
        }
Ejemplo n.º 14
0
        public void TestSpriteDrawWithDefaultValuesAndTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);
            var transform = new SpriteTransform(translation: new Vector(3, 5), rotation: HalfPI, scale: 0.5f, color: Color.Blue);

            var expected = CreateDrawImageParams(source, origin,
                destination: new Rectangle(3, 5, 10, 10), rotation: HalfPI, color: Color.Blue);

            // ARRANGE
            var sprite = CreateSprite(source, origin);

            DrawImageParams actual = null;
            var drawContext = CreateDrawContextMock(p => actual = p);

            // ACT
            sprite.Draw(drawContext.Object, transform);

            // ASSERT
            drawContext.VerifyAll();
            AssertDrawImageParamsAreEquals(expected, actual);
        }
Ejemplo n.º 15
0
        public void TestSpriteCompositeDrawWithDefaultValuesAndTransform()
        {
            var source1 = new RectangleInt(10, 10, 20, 20);
            var source2 = new RectangleInt(40, 40, 30, 30);
            var origin = new Vector(4, 7);
            var transform = new SpriteTransform(translation: new Vector(-20, -10), rotation: -2.2f, scale: 5.0f, color: Color.Green);

            var expected1 = CreateDrawImageParams(source1, origin,
                destination: new Rectangle(-20, -10, 100, 100), rotation: -2.2f, color: Color.Green);

            var expected2 = CreateDrawImageParams(source2, origin,
                destination: new Rectangle(-20, -10, 150, 150), rotation: -2.2f, color: Color.Green);

            // ARRANGE
            var sprite1 = CreateSprite(source1, origin);
            var sprite2 = CreateSprite(source2, origin);
            var spriteComposite = new SpriteComposite("tata", new[] { sprite1, sprite2 });

            DrawImageParams actual1 = null;
            DrawImageParams actual2 = null;
            var callCount = 0;
            var drawContext = CreateDrawContextMock(p =>
            {
                callCount++;
                if (callCount == 1) actual1 = p;
                if (callCount == 2) actual2 = p;
            });

            // ACT
            spriteComposite.Draw(drawContext.Object, transform);

            // ASSERT
            drawContext.VerifyAll();
            Assert.AreEqual(2, callCount);
            AssertDrawImageParamsAreEquals(expected1, actual1);
            AssertDrawImageParamsAreEquals(expected2, actual2);
        }
        public void TestIdentityRotate()
        {
            var transform = new SpriteTransform();

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(0.0f, final.Rotation);
        }
        public void TestScalingAfterTranslation()
        {
            var transform1 = new SpriteTransform(translation: new Vector(100, 100));
            var transform2 = new SpriteTransform(transform1, scale: 2.0f);

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(new Vector(100, 100), final.Translation);
            Assert.AreEqual(2.0f, final.Scale);
        }
        public void TestTranslationAfterRotation()
        {
            var transform1 = new SpriteTransform(rotation: HalfPI);
            var transform2 = new SpriteTransform(transform1, new Vector(100, 0));

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(new Vector(0, 100), final.Translation);
            Assert.AreEqual(HalfPI, final.Rotation);
        }
        public void TestTranslationAfterRotationAndTranslate()
        {
            var transform1 = new SpriteTransform(translation: new Vector(100, 100), rotation: HalfPI * 2);
            var transform2 = new SpriteTransform(transform1, new Vector(50, 25));

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(new Vector(50, 75), final.Translation);
            Assert.AreEqual(HalfPI * 2, final.Rotation);
        }
        public void TestTranslationWithSimpleComposition()
        {
            var transform1 = new SpriteTransform(translation: new Vector(98, 76));
            var transform2 = new SpriteTransform(transform1);

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(new Vector(98, 76), final.Translation);
        }
        public void TestTranslationNoComposition()
        {
            var transform = new SpriteTransform(translation: new Vector(123, 456));

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(new Vector(123, 456), final.Translation);
        }
Ejemplo n.º 22
0
 protected bool Equals(SpriteTransform other)
 {
     return base.Equals(other)
         && this.Color.Equals(other.Color);
 }
 public SpriteAnimationTemplate AddFrame(SpriteDefinition frameSprite, float duration, SpriteTransform transform = null)
 {
     this.frames.Add(new SpriteAnimationFrameTemplate(frameSprite, duration, transform));
     return this;
 }
        public void TestScaleNoComposition()
        {
            var transform = new SpriteTransform(scale: 6.6f);

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(6.6f, final.Scale);
        }
Ejemplo n.º 25
0
        public void TestSpriteDrawWithColorAndTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);
            var transform = new SpriteTransform(color: new Color(128, 128, 128, 128));

            var expected = CreateDrawImageParams(source, origin,
                destination: new Rectangle(0, 0, 20, 20), color: new Color(111, 122, 94, 72));

            // ARRANGE
            var sprite = CreateSprite(source, origin);
            sprite.Color = new Color(222, 244, 188, 144);

            DrawImageParams actual = null;
            var drawContext = CreateDrawContextMock(p => actual = p);

            // ACT
            sprite.Draw(drawContext.Object, transform);

            // ASSERT
            drawContext.VerifyAll();
            AssertDrawImageParamsAreEquals(expected, actual);
        }
Ejemplo n.º 26
0
        public override int Draw(IDrawContext drawContext, Transform transform)
        {
            var newTransform = new SpriteTransform(transform, this.Position, this.Rotation, this.Scale, this.Color);

            return this.Children.Cast<SpriteBase>().Sum(sprite => sprite.Draw(drawContext, newTransform));
        }
Ejemplo n.º 27
0
        public void TestSpriteDrawWithPositionAndTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);
            var transform = new SpriteTransform(translation: new Vector(11, 13));

            var expected = CreateDrawImageParams(source, origin, destination: new Rectangle(-1, 37, 20, 20));

            // ARRANGE
            var sprite = CreateSprite(source, origin);
            sprite.Position = new Vector(-12, 24);

            DrawImageParams actual = null;
            var drawContext = CreateDrawContextMock(p => actual = p);

            // ACT
            sprite.Draw(drawContext.Object, transform);

            // ASSERT
            drawContext.VerifyAll();
            AssertDrawImageParamsAreEquals(expected, actual);
        }
 public SpriteCompositeTemplate AddTemplate(ISpriteTemplate template, SpriteTransform transform = null)
 {
     return this.AddTemplate(transform, template);
 }
        public void TestIdentityScale()
        {
            var transform = new SpriteTransform();

            var final = transform.GetSpriteFinal();

            Assert.AreEqual(1.0f, final.Scale);
        }
        public void TestTranslationAfterScalingAndTranslate()
        {
            var transform1 = new SpriteTransform(translation: new Vector(15, -25), scale: 2.0f);
            var transform2 = new SpriteTransform(transform1, new Vector(100, 100));

            var final = transform2.GetSpriteFinal();

            Assert.AreEqual(new Vector(215, 175), final.Translation);
            Assert.AreEqual(2.0f, final.Scale);
        }