Example #1
0
 public static Sprite CreateSprite(Texture2D texture, Vector2 position, Nullable<Vector2> origin, SpriteAnimation spriteAnimation, ModularAnimation ModularAnimation, Color color, string name)
 {
     Sprite s = new Sprite(texture, position, new Vector2(1,1), 0, color, 1, name, 2);
     s.SetOrigin(origin);
     s.AddAnimation(spriteAnimation);
     s.AddModularAnimation(ModularAnimation);
     return s;
 }
Example #2
0
 public int AddAnimationToComponent(string componentName, SpriteAnimation animation)
 {
     for (int x = 0; x < this.children.Count(); x++)
     {
         if (this.children[x].name == componentName)
         {
             this.children[x].AddAnimation(animation);
             return 1;
         }
     }
     return 0;
 }
Example #3
0
 public void AddAnimation(SpriteAnimation animation)
 {
     if (animation == null)
     {
         this.spriteAnimation = null;
     }
     else
     {
         this.spriteAnimation = animation;
     }
     this.SetOverloadIndex();
 }
        public static SpriteAnimation Load(string animationName)
        {
            String line;
            int numberOfFrames;
            try
            {
                using (StreamReader sr = new StreamReader("Content/Animations/SpriteAnimations/"  + animationName + ".txt"))
                {
                    line = sr.ReadToEnd();
                }
                string[] frames = line.Split('|');
                numberOfFrames = frames.Count() - 1;

                if (numberOfFrames <= 0)
                {
                    throw new Exception();
                }

                List<SpriteAnimation.Frame> spriteFrames = new List<SpriteAnimation.Frame>();

                //Go through each frame in the array and add it to the list of frames
                for (int s = 0; s < numberOfFrames; s++)
                {
                    string[] frameComponents = frames[s].Split(',');

                    float duration;
                    int x;
                    int y;
                    int width;
                    int height;

                    float.TryParse(frameComponents[0], NumberStyles.Any, CultureInfo.InvariantCulture, out duration);
                    Int32.TryParse(frameComponents[1], out x);
                    Int32.TryParse(frameComponents[2], out y);
                    Int32.TryParse(frameComponents[3], out width);
                    Int32.TryParse(frameComponents[4], out height);

                    SpriteAnimation.Frame tempFrame = new SpriteAnimation.Frame();
                    tempFrame.duration = duration;
                    tempFrame.source = new Rectangle(x, y, width, height);
                    spriteFrames.Add(tempFrame);
                }
                SpriteAnimation spriteAnimation = new SpriteAnimation(spriteFrames);
                return spriteAnimation;
            }
            catch (Exception e)
            {
                return null;
            }
        }