Beispiel #1
0
        private void LoadFrames(string dataPath)
        {
            XmlReader xmlReader = XmlReader.Create(dataPath);

            while (xmlReader.Read())
            {
                if (xmlReader.IsStartElement("sprite"))
                {
                    string frameName = xmlReader.GetAttribute("name");
                    if (frameName.Contains(Name))
                    {
                        SpriteFrame animationFrame = new SpriteFrame();
                        animationFrame.Name              = frameName;
                        animationFrame.SourceRect.X      = Convert.ToInt32(xmlReader.GetAttribute("x"));
                        animationFrame.SourceRect.Y      = Convert.ToInt32(xmlReader.GetAttribute("y"));
                        animationFrame.SourceRect.Width  = Convert.ToInt32(xmlReader.GetAttribute("width"));
                        animationFrame.SourceRect.Height = Convert.ToInt32(xmlReader.GetAttribute("height"));

                        allFrames.Add(animationFrame);
                    }
                }
            }
        }
Beispiel #2
0
        private void UpdateAnimationFrame(GameTime gameTime)
        {
            timer += gameTime.ElapsedGameTime.Milliseconds;

            if (currentFrames.Count == 0)
            {
                throw new Exception("No current animation set");
            }

            if (timer > FrameDelay)
            {
                timer = 0;
                if (currentFrameCount < currentFrames.Count - 1) // wenn der aktulle frame nicht der letzte ist
                {
                    currentFrameCount++;                         // dann einen frame weiter zählen
                }
                else
                {
                    currentFrameCount = 0; // sonst wieder vorne anfangen
                }
                CurrentFrame = currentFrames[currentFrameCount];
            }
        }