Beispiel #1
0
        public void PlayAnimation(string name)
        {
            if (currentAnimationName != name)
            {
                currentFrames = allFrames.FindAll(animationFrame => animationFrame.Name.Contains(name));
                currentAnimationName = name;
                currentFrameCount = 0;
                CurrentFrame = currentFrames[0];

                if (currentFrames.Count == 0)
                    throw new Exception(string.Format("No AnimationFrame found for {0}", name));
            }
        }
Beispiel #2
0
        public void LoadFrame(string dataPath)
        {
            XmlReader xmlReader = XmlReader.Create(dataPath);

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

                        allItems.Add(animationFrame);
                    }
                }
            }
        }
Beispiel #3
0
        private void UpdateCurrentAnimationFrame(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)
                    currentFrameCount++;
                else
                    currentFrameCount = 0;

                CurrentFrame = currentFrames[currentFrameCount];
                LastFrame = CurrentFrame;
            }
        }
Beispiel #4
0
 public void SetFrame(string name)
 {
     // name is assigned
     CurrentItem = allItems.Find(animationFrame => animationFrame.Name.Contains(name));
     ItemsToDraw.Add(CurrentItem);
 }