/// <summary>
        ///     Proces method that is called by the content pipeline.
        /// </summary>
        /// <remarks>
        ///     If you are using this processor without the assistance of the Content Pipeline Tool,
        ///     then the other Process(AsepriteImporterResult) overload should be used instead.
        /// </remarks>
        /// <param name="input">
        ///     The <see cref="AsepriteImporterResult"/> instance created as part
        ///     of the import process.
        /// </param>
        /// <param name="context"></param>
        /// <returns>
        ///     A new <see cref="AsepriteDocumentProcessorResult"/> instance containing the result
        ///     of the processing.
        /// </returns>
        public override AsepriteDocumentProcessorResult Process(AsepriteImporterResult input, ContentProcessorContext context)
        {
            AsepriteDocumentProcessorOptions options = new AsepriteDocumentProcessorOptions
            {
                BorderPadding        = BorderPadding,
                IgnoreEmptyFrames    = IgnoreEmptyFrames,
                InnerPadding         = InnerPadding,
                MergeDuplicateFrames = MergeDuplicateFrames,
                OnlyVisibleLayers    = OnlyVisibleLayers,
                SheetType            = SheetType,
                Spacing = Spacing
            };

            //  Read the aseprite document from the stream.
            AsepriteDocument doc;

            using (MemoryStream stream = new MemoryStream(input.Data))
            {
                using (AsepriteReader reader = new AsepriteReader(stream))
                {
                    doc = new AsepriteDocument(reader);;
                }
            }

            //  Convert the document into an AnimationProcessorResult.
            AsepriteDocumentProcessorResult result = new AsepriteDocumentProcessorResult(doc, options);

            return(result);
        }
Example #2
0
        public void LoadContent()
        {
            AsepriteDocument aseDoc = Game.Content.Load <AsepriteDocument>("dino");

            //  Create a new AnimatedSprite from the document
            dinoSprite = new AnimatedSprite(aseDoc);
        }
Example #3
0
        /// <summary>
        /// Create an animation with a AsepriteDocument defined with a tag.
        /// </summary>
        /// <param name="doc">The document to derive the frames from</param>
        /// <param name="tag">A tag defining a range of frames within the document</param>
        internal Animation(ref AsepriteDocument doc, string tag)
        {
            this.tag = tag;

            ///Attempt to extract an Asetag from the doc with the tag
            AsepriteTag aseTag = doc.Tags[tag];

            if (aseTag != null)
            {
                //Get the framerange from the tag
                frameRange = new int[] { aseTag.From, aseTag.To };
                //Get the frames from the doc in the range
                frames = new AsepriteFrame[frameRange[1] - frameRange[0] + 1];
                for (int i = 0; i < frames.Length; i++)
                {
                    frames[i] = doc.Frames[frameRange[0] + i];
                }

                currentFrameIndex = 0;
            }
            else
            {
                Console.WriteLine("Tag: " + tag + ", does not exist!");
            }
        }
Example #4
0
 /// <summary>
 ///     Creates a new <see cref="AsepriteDocumentProcessorResult"/> instance.
 /// </summary>
 /// <param name="document">
 ///     The <see cref="AsepriteDocument"/> instance that was created from processing
 ///     the Aseprite file.
 /// </param>
 /// <param name="options">
 ///     The <see cref="AsepriteDocumentProcessorOptions"/> instance containing the values
 ///     supplied by the user in the content pipeline properties window.
 /// </param>
 public AsepriteDocumentProcessorResult(AsepriteDocument document, AsepriteDocumentProcessorOptions options)
 {
     _document = document;
     Options   = options;
     GetPalette();
     GetAnimations();
     CreateTexture();
     GetSlices();
 }
Example #5
0
        /// <summary>
        ///     Creates a new <see cref="AnimatedSprite"/> instance.
        /// </summary>
        /// <param name="aseprite">
        ///     An <see cref="AsepriteDocument"/> instace created by
        ///     importing from the content pipeline.
        /// </param>
        /// <param name="position">
        ///     The top-left xy-coordinate position.
        /// </param>
        public AnimatedSprite(AsepriteDocument aseprite, Vector2 position)
            : this(aseprite.Texture, position)
        {
            for (int i = 0; i < aseprite.Frames.Count; i++)
            {
                Frames.Add(new Frame()
                {
                    Bounds   = new Rectangle(aseprite.Frames[i].X, aseprite.Frames[i].Y, aseprite.Frames[i].Width, aseprite.Frames[i].Height),
                    Duration = aseprite.Frames[i].Duration
                });
            }

            foreach (KeyValuePair <string, AsepriteTag> kvp in aseprite.Tags)
            {
                Animation animation = new Animation()
                {
                    Name      = kvp.Value.Name,
                    From      = kvp.Value.From,
                    To        = kvp.Value.To,
                    Direction = (AnimationLoopDirection)kvp.Value.Direction,
                    IsOneShot = kvp.Value.IsOneShot
                }
                ;
                Animations.Add(animation.Name, animation);
            }

            foreach (KeyValuePair <string, AsepriteSlice> kvp in aseprite.Slices)
            {
                Slice slice = new Slice
                {
                    Name  = kvp.Value.Name,
                    Color = kvp.Value.Color,
                    Keys  = new Dictionary <int, SliceKey>()
                };

                foreach (KeyValuePair <int, AsepriteSliceKey> innerKVP in kvp.Value.SliceKeys)
                {
                    SliceKey key = new SliceKey()
                    {
                        Bounds = new Rectangle(innerKVP.Value.X, innerKVP.Value.Y, innerKVP.Value.Width, innerKVP.Value.Height),
                        Frame  = innerKVP.Value.FrameIndex,
                        Color  = slice.Color
                    };

                    slice.Keys.Add(key.Frame, key);
                }
                Slices.Add(slice.Name, slice);
            }

            Play(Animations.First().Key);
        }
Example #6
0
        /// <summary>
        /// Constructor for an animation with a doc with no tags (Only so the game doesn't crash, Use tags!)
        /// </summary>
        /// <param name="doc">The document to derive the frames from</param>
        internal Animation(ref AsepriteDocument doc)
        {
            tag = doc.Texture.Name;

            //Get the framerange from the doc
            frameRange = new int[] { 0, doc.Frames.Count - 1 };
            //Get the frames from the doc in the range
            frames = new AsepriteFrame[frameRange[1] - frameRange[0] + 1];
            for (int i = 0; i < frames.Length; i++)
            {
                frames[i] = doc.Frames[frameRange[0] + i];
            }

            currentFrameIndex = 0;
        }
Example #7
0
        /// <summary>
        /// Creates a controller that handles the animations in the AsepriteDocument.
        /// </summary>
        /// <param name="doc">the AsepriteDocument that is to be handled by the controller.</param>
        internal AnimationController(string assetName)
        {
            doc = Game.aseDocs.Get(assetName);

            this.assetName = assetName;
            if (doc.Tags.Count > 0)
            {
                string defaultTag = doc.Tags.Keys.Where(key => key.StartsWith("DE-")).ToList()[0];
                defaultAnimation = new Animation(ref doc, defaultTag);
                if (containsHitBoxAnimation)
                {
                    hitBoxDoc = Game.aseDocs.Get(assetName + "_BOX");
                }
            }
            else
            {
                Console.WriteLine($"[ERROR] {assetName} has no tags.");
                defaultAnimation = new Animation(ref doc);
            }
            currentAnimation = defaultAnimation;
        }
Example #8
0
 /// <summary>
 ///     Creates a new <see cref="AnimatedSprite"/> instance.
 /// </summary>
 /// <param name="aseprite">
 ///     An <see cref="AsepriteDocument"/> instace created by
 ///     importing from the content pipeline.
 /// </param>
 public AnimatedSprite(AsepriteDocument aseprite)
     : this(aseprite, Vector2.Zero)
 {
 }