Пример #1
0
        public static AnimationSet CreateSingleSprite(Sprite sprite)
        {
            AnimationSet animationSet = new AnimationSet();

            animationSet.importOrigin = sprite.origin;
            animationSet.AddStaticDefaultAnimation(new Cel(sprite));
            animationSet.FinishGeneration();
            return(animationSet);
        }
Пример #2
0
        /// <summary>Check that an AnimationSet round-trips through serialization cleanly</summary>
        public void RoundTripCheck(GraphicsDevice graphicsDevice, bool useExternalImages)
        {
            // Serialize a first time
            var         firstMemoryStream = new MemoryStream();
            var         firstBinaryWriter = new BinaryWriter(firstMemoryStream);
            ImageWriter firstImageWriter  = null;

            if (useExternalImages)
            {
                firstImageWriter = new ImageWriter();
                RegisterImages(firstImageWriter);
                firstImageWriter.WriteOutAllImages(firstMemoryStream);
            }

            var firstSerializeContext = new AnimationSerializeContext(firstBinaryWriter, firstImageWriter);

            Serialize(firstSerializeContext);
            var originalData = firstMemoryStream.ToArray();

            // Then deserialize that data
            var         br          = new BinaryReader(new MemoryStream(originalData));
            ImageBundle imageBundle = null;

            if (useExternalImages)
            {
                var helper = new SimpleTextureLoadHelper(graphicsDevice);
                imageBundle            = new ImageBundle();
                br.BaseStream.Position = imageBundle.ReadAllImages(originalData, (int)br.BaseStream.Position, helper);
            }

            var deserializeContext = new AnimationDeserializeContext(br, imageBundle, graphicsDevice);
            var deserialized       = new AnimationSet(deserializeContext);

            // Then serialize that deserialized data and see if it matches
            // (Ideally we'd recursivly check the AnimationSet to figure out if it matches, but that's a bit too hard)
            var         secondMemoryStream = new MemoryCompareStream(originalData);
            var         secondBinaryWriter = new BinaryWriter(secondMemoryStream);
            ImageWriter secondImageWriter  = null;

            if (useExternalImages)
            {
                secondImageWriter = new ImageWriter();
                deserialized.RegisterImages(secondImageWriter);
                secondImageWriter.WriteOutAllImages(secondMemoryStream);
            }

            var secondSerializeContext = new AnimationSerializeContext(secondBinaryWriter, secondImageWriter);

            deserialized.Serialize(secondSerializeContext);

            // Clean-up:
            if (imageBundle != null)
            {
                imageBundle.Dispose();
            }
        }