Advertisement
Guest User

Untitled

a guest
May 28th, 2015
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Xml.Serialization;
  3. using Microsoft.Xna.Framework;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using Microsoft.Xna.Framework.Storage;
  7.  
  8. using System.IO;
  9.  
  10. namespace RiskyRain2
  11. {
  12.     [Serializable]
  13.     public class AnimationData
  14.     {
  15.         Dictionary<string, Rectangle> spriteSourceRectangles = new Dictionary<string, Rectangle>();
  16.  
  17.         public AnimationData(string epath)
  18.         {
  19.            
  20.             string path = epath;
  21.             // open a StreamReader to read the index
  22.             using (StreamReader reader = new StreamReader(path))
  23.             {
  24.                 // while we're not done reading...
  25.                 while (!reader.EndOfStream)
  26.                 {
  27.                     // get a line
  28.                     string line = reader.ReadLine();
  29.  
  30.                     // split at the equals sign
  31.                     string[] sides = line.Split('=');
  32.  
  33.                     // trim the right side and split based on spaces
  34.                     string[] rectParts = sides[1].Trim().Split(' ');
  35.  
  36.                     // create a rectangle from those parts
  37.                     Rectangle r = new Rectangle(
  38.                         int.Parse(rectParts[0]),
  39.                         int.Parse(rectParts[1]),
  40.                         int.Parse(rectParts[2]),
  41.                         int.Parse(rectParts[3]));
  42.  
  43.                     // add the name and rectangle to the dictionary
  44.                     spriteSourceRectangles.Add(sides[0].Trim(), r);
  45.                 }
  46.             }
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement