protected void drawFrame(Frame frame, SpriteBatch spriteBatch) { if (frame == null) return; int numComponents = frame.NumComponents; for (int i = 0; i < numComponents; ++i) { FrameComponent component = frame.getComponent(i); TileSet tileSet = Game1.Instance.gameData.tileSets[component.TileSetIndex]; Rectangle tileDims = component.getTileRect(tileSet); Rectangle pos = new Rectangle(Left + component.Left, Top + component.Top, tileDims.Width, tileDims.Height); spriteBatch.Draw(tileSet.texture, pos, tileDims, Color.White); } }
private List<Frame> getFrames(XElement animationData) { List<Frame> frames = new List<Frame>(); foreach (XElement frameData in animationData.Elements("frame")) { int frameTime = (int)frameData.Attribute("frameTime"); //go through all the component xml data in the frame and create a list of of the components List<FrameComponent> components = getFrameComponents(frameData); Frame frame = new Frame(frameTime, components); frames.Add(frame); } return frames; }
/* *********************************** * Methods Relating to Animation * *************************************/ /* * Create animation object from sprite sheet and frame names. * * */ public Animation AnimationForFrameNames(String[] frameNames, int frameTime, Color frameColor, bool isLooping) { // create animation object. Animation animation = new Animation(); // create frames array. Frame[] frames = new Frame[frameNames.Length]; // loop through frameNames and poplulate Frame array. for ( int i = 0; i < frameNames.Length; i++ ) { frames[i] = SpriteFrameByFrameName(frameNames[i]); } // initialize animation and return. animation.Initialize(_texture, frames, frameTime, frameColor, isLooping); return animation; }