/// <summary> /// Constructor. /// </summary> public BackgroundScreen() { TransitionOnTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); SpriteTexture = new AnimatedTexture(Vector2.Zero, Rotation, Scale, Depth); }
// reads xml and loads textures and actions for this animated entity. Can be called from outside this class public void readXML(string entityFolder, string entityName) { //XmlTextReader textReader = new XmlTextReader(SB.content.RootDirectory + "/xml/characters/" + entityName); XDocument xml = XDocument.Load(SB.content.RootDirectory + "/xml/" + entityFolder + "/" + entityName + ".xml"); AnimatedEntityData data = new AnimatedEntityData(); // read IEnumerable<XElement> animatedEntityList = xml.Descendants("animatedEntity"); foreach (XElement animatedEntityNode in animatedEntityList) { if (animatedEntityNode.Attribute("idleOffset") != null) { data.idleOffset = animatedEntityNode.Attribute("idleOffset").Value.toBool(); } } // read all the animatedTextures and actions of the character IEnumerable<XElement> animatedTextureList = xml.Descendants("animatedTexture"); int textureNumber = 0; foreach (XElement animatedTextureNode in animatedTextureList) { AnimatedTexture animatedTexture = new AnimatedTexture(); animatedTexture.id = textureNumber; string textureName = animatedTextureNode.Attribute("name").Value; animatedTexture.texture = TextureManager.Instance.getTexture(entityFolder, textureName); animatedTexture.frameWidth = animatedTextureNode.Attribute("frameWidth").Value.toFloat(); animatedTexture.frameHeight = animatedTextureNode.Attribute("frameHeight").Value.toFloat(); animatedTexture.columns = animatedTextureNode.Attribute("columns").Value.toInt(); animatedTexture.rows = animatedTextureNode.Attribute("rows").Value.toInt(); float width = animatedTexture.texture.Width; float height = animatedTexture.texture.Height; animatedTexture.frameWidthUV = animatedTexture.frameWidth / width; animatedTexture.frameHeightUV = animatedTexture.frameHeight / height; IEnumerable<XElement> actionList = animatedTextureNode.Descendants("action"); foreach (XElement actionNode in actionList) { AnimationAction action = new AnimationAction(); action.textureId = textureNumber; action.name = actionNode.Attribute("name").Value; if (actionNode.Attribute("from") != null) { action.from = actionNode.Attribute("from").Value; } else { action.from = null; } if (actionNode.Attribute("to") != null) { action.to = actionNode.Attribute("to").Value; } else { action.to = null; } action.initialFrame = actionNode.Attribute("initialFrame").Value.toInt() - 1; action.endFrame = actionNode.Attribute("endFrame").Value.toInt() - 1; if (actionNode.Attribute("FPS") != null) { action.FPS = actionNode.Attribute("FPS").Value.toFloat(); } else { action.FPS = 30; } if (actionNode.Attribute("loops") != null) { action.loops = actionNode.Attribute("loops").Value.toBool(); } else { action.loops = false; } if (actionNode.Attribute("playAtEnd") != null) { action.playAtEnd = actionNode.Attribute("playAtEnd").Value; } else { action.playAtEnd = null; } // if there is playRandom attribute, read all the random actions if (actionNode.Attribute("playRandom") != null) { action.playRandom = actionNode.Attribute("playRandom").Value.toBool(); if (action.playRandom) { action.playRandomMin = actionNode.Attribute("playRandomMin").Value.toFloat(); action.playRandomMax = actionNode.Attribute("playRandomMax").Value.toFloat(); action.randomActions = new List<RandomAction>(); IEnumerable<XElement> randomActionsList = actionNode.Descendants("playRandom"); foreach (XElement randomActionNode in randomActionsList) { RandomAction randomAction = new RandomAction(); randomAction.name = randomActionNode.Attribute("name").Value; if (randomActionNode.Attribute("probability") != null) { randomAction.probability = randomActionNode.Attribute("probability").Value.toFloat(); } else { randomAction.probability = 1.0f; } action.randomActions.Add(randomAction); } } } // add each action to the list data.actions[action.name] = action; action.initialize(); } // add each animated texture with all its actions to the list data.animatedTextures.Add(animatedTexture); ++textureNumber; } datas[entityFolder + "/" + entityName] = data; }