private void ParseAnim(string url) { GraphicsDevice gd = PrimalDevistation.Instance.GD; ContentManager cm = PrimalDevistation.Instance.CM; XmlDocument doc = new XmlDocument(); doc.Load(url); // Create the weapon and set its name XmlNode spriteNode = doc.SelectSingleNode("sprite"); string imageURL = spriteNode.Attributes["img"].Value; Texture2D tex = cm.Load <Texture2D>(imageURL); Color[,] texData = GetFramesetData(tex); XmlNodeList animNodes = spriteNode.SelectNodes("animation"); foreach (XmlNode node in animNodes) { cAnim a = new cAnim(); a.Name = node.Attributes["name"].Value; if (node.Attributes["loop"] != null) { a.AnimType = GetAnimType(node.Attributes["loop"].Value); } if (node.Attributes["animLength"] != null) { a.AnimLength = int.Parse(node.Attributes["animLength"].Value); } _animations.Add(a.Name, a); XmlNodeList frameNodes = node.SelectNodes("frame"); foreach (XmlNode frameNode in frameNodes) { int x = int.Parse(frameNode.Attributes["x"].Value); int y = int.Parse(frameNode.Attributes["y"].Value); int w = int.Parse(frameNode.Attributes["w"].Value); int h = int.Parse(frameNode.Attributes["h"].Value); Texture2D frameTex = new Texture2D(gd, w, h, 1, TextureUsage.None, SurfaceFormat.Color); frameTex.SetData <Color>(GetArrayForFrame(texData, x, y, w, h)); a.FramesColData.Add(cGraphics.GetCollisionData(frameTex)); a.Frames.Add(frameTex); } } }
public void Play(string animName) { _currentAnim = _animations[animName]; _animTimer = 0; }