/// <summary> /// Loads the frames of the animation /// </summary> /// <param name="framesStruct">Struct containing all the information needed to load the frames</param> public void LoadFrames(IAnimationFrames frames) { SpritesheetAnimationFrames animationFrames = (SpritesheetAnimationFrames)frames; currentFrame.Texture = animationFrames.spriteSheet; currentFrame.DrawArea = animationFrames.drawAreas[0]; currentFrame.origin = animationFrames.origin; drawAreas = animationFrames.drawAreas; frameIndex = 0; }
/// <summary> /// Loads an animation based on the name of the texture previouly from a spritesheet. Texture should have been /// previously loaded in the resource manager. Set the number of rows and columns /// and choose the row that contains the animation /// Animation are loaded from a spritesheet from a row /// </summary> /// <param name="animationName">Name to be given to the state and the animation</param> /// <param name="textureName">Name of the texture file/ spritesheet</param> /// <param name="numRows">Number of rows that the spritesheet has</param> /// <param name="numCols">Number of cols that the spritesheet has</param> /// <param name="row">Row of the animation </param> /// <returns>Returns the state created that hold the animation</returns> public IAnimationState LoadAnimation(string animationName, string textureName, int numRows, int numCols, int row) { //Creates a new animation IAnimationState animation = ASMachine.LoadState <SpritsheetAnimation>(animationName); //Get the texture/ spritesheet fro mthe resources texture = resourceManager.GetTexture(textureName); //Calculates the width and height of each frame int width = texture.Width / numCols; int height = texture.Height / numRows; //Calculates the pixels of the specific row to get the various frames int y = (height) * (row - 1); List <Rectangle> drawAreas = new List <Rectangle>(); int x = 0; //Gets all the textures of a specific row while (true) { drawAreas.Add(new Rectangle(x, y, width, height)); x += width; if (x + width >= texture.Width) { break; } } //Loads all the animation frames found into the animation SpritesheetAnimationFrames animationFrames = new SpritesheetAnimationFrames(); animationFrames.drawAreas = drawAreas.ToArray(); animationFrames.spriteSheet = texture; animationFrames.origin = new Vector2(drawAreas[0].Width / 2, drawAreas[0].Height / 2); animation.LoadFrames(animationFrames); return(animation); }