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

            // 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)
                .AddFrame(definition2, 2.5f);

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

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

            // ASSERT
            AssertSprite.AnimationEqual(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 TestDefaultValueForEmptyAnimation()
        {
            var expected = new SpriteAnimation("tata", new SpriteAnimationFrame[] { });

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var template = spriteSheet.AddSpriteAnimationTemplate("tata");

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

            // ASSERT
            AssertSprite.AnimationEqual(expected, actual);
        }
Exemplo n.º 4
0
        private SpriteLayer CreateSpriteLayer()
        {
            var texture = this.ResourceManager.GetTexture(@"Sandbox\LinkSheet");
            var sheet = new SpriteSheet(texture, "Link");
            sheet.AddSpriteDefinition("Link01", new RectangleInt(3, 3, 16, 22), new Vector(8, 11));
            sheet.AddSpriteDefinition("Sleep01", new RectangleInt(45, 219, 32, 40));

            var la1 = sheet.AddSpriteDefinition("LinkAnim01", new RectangleInt(187, 270, 28, 28), new Vector(07, 25));
            var la2 = sheet.AddSpriteDefinition("LinkAnim02", new RectangleInt(225, 273, 31, 22), new Vector(07, 19));
            var la3 = sheet.AddSpriteDefinition("LinkAnim03", new RectangleInt(268, 270, 26, 28), new Vector(06, 19));
            var la4 = sheet.AddSpriteDefinition("LinkAnim04", new RectangleInt(303, 266, 17, 35), new Vector(06, 19));
            var la5 = sheet.AddSpriteDefinition("LinkAnim05", new RectangleInt(328, 269, 26, 30), new Vector(17, 19));
            var la6 = sheet.AddSpriteDefinition("LinkAnim06", new RectangleInt(355, 273, 32, 22), new Vector(23, 19));
            var la7 = sheet.AddSpriteDefinition("LinkAnim07", new RectangleInt(389, 271, 24, 25), new Vector(16, 22));
            var la8 = sheet.AddSpriteDefinition("LinkAnim08", new RectangleInt(423, 268, 16, 31), new Vector(08, 28));

            //var linkAnimTemplate = new SpriteAnimationTemplate("LinkAnim")
            var linkAnimTemplate = sheet.AddSpriteAnimationTemplate("LinkAnim")
                .AddFrame(la1, 0.1f)
                .AddFrame(la2, 0.1f)
                .AddFrame(la3, 0.1f)
                .AddFrame(la4, 0.1f)
                .AddFrame(la5, 0.1f)
                .AddFrame(la6, 0.1f)
                .AddFrame(la7, 0.1f)
                .AddFrame(la8, 0.1f);

            var crystal = sheet.AddSpriteDefinition("Crystal", new RectangleInt(336, 221, 10, 14), new Vector(4, 6));

            //this.linkCompositeTemplate = new SpriteCompositeTemplate("CompositeLink")
            this.linkCompositeTemplate = sheet.AddSpriteCompositeTemplate("CompositeLink")
                .AddTemplate(linkAnimTemplate)
                .AddTemplate(crystal, new SpriteTransform(translation: new Vector(20, 0)));

            //sheet.Save(@"C:\Users\Pascal\Dev\DotNet\GitHub\XNAGameEngine2D\Link SpriteSheet.xml");

            var link01 = new Sprite(sheet, "Link01") { Position = this.player, Color = Color.Blue, Scale = 2, ShouldDrawPixelPrecision = true };
            this.sleep01 = new Sprite(sheet, "Sleep01") { Position = new Vector(125, 25), FlipVertically = true };

            this.ResourceManager.AddSpriteSheet(sheet);

            var spriteLayer = new SpriteLayer("Sprites");
            spriteLayer.AddSprite(link01);
            spriteLayer.AddSprite(this.sleep01);
            spriteLayer.ParallaxScrollingVector = new Vector(4.0f, 8.0f);
            spriteLayer.Offset = new Vector(50, 50);

            return spriteLayer;
        }