usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingMicrosoft.Xna.Framework;usingMicrosoft.Xna.Framework.Audio;usingMicrosoft.Xna.Framework.Content;usingMicrosoft.Xna.Framework.GamerServices;usingMicrosoft.Xna.Framework.Graphics;usingMicrosoft.Xna.Framework.Input;usingMicrosoft.Xna.Framework.Media;namespacewindowsgame1{/// <summary> ///This is the main type for your game/// </summary> Public classGame1:Microsoft.Xna.Framework.Game {Graphicsdevicemanager graphics; SpriteBatch SpriteBatch; Texture2d texture; //the length and width of the image arePoint framesize =NewPoint ( the, the); Point Currentframe=NewPoint (0,0); //8 rows 6 colsPoint sheetsize =NewPoint (6,8); PublicGame1 () {graphics=NewGraphicsdevicemanager ( This); Content.rootdirectory="Content"; } /// <summary> ///allows the game to perform any initialization it needs to before starting to run. ///This is the where it can query for any required services and load any non-graphic///related content. Calling base. Initialize'll enumerate through any///and initialize them as well. /// </summary> protected Override voidInitialize () {//Todo:add Your initialization logic here Base. Initialize (); } /// <summary> ///loadcontent'll be called once per game and was the place to load///All of your content. /// </summary> protected Override voidloadcontent () {//Create A new spritebatch, which can be used to draw textures.SpriteBatch =NewSpriteBatch (GraphicsDevice); //Todo:use this. Content to load your game content hereTexture= Content.load<texture2d> (@"images\threerings"); } /// <summary> ///unloadcontent'll be called once per game and was the place to unload///All content. /// </summary> protected Override voidunloadcontent () {//todo:unload any non contentmanager content here } /// <summary> ///allows the game to run logic such as updating,///checking for collisions, gathering input, and playing audio. /// </summary> /// <param name= "GameTime" >provides a snapshot of timing values.</param> protected Override voidUpdate (GameTime GameTime) {//allows the game to exit if(Gamepad.getstate (Playerindex.one). Buttons.back = =buttonstate.pressed) This. Exit (); //Todo:add Your update logic herecurrentframe.x++; if(Currentframe.x >=sheetsize.x) {currentframe.x=0; ++currentframe.y; if(Currentframe.y >=sheetsize.y) Currentframe.y=0; } Base. Update (GameTime); } /// <summary> ///This was called when the game should draw itself. /// </summary> /// <param name= "GameTime" >provides a snapshot of timing values.</param> protected Override voidDraw (GameTime GameTime) {graphicsdevice.clear (color.cornflowerblue); //Todo:add your drawing code here//notifies the video card to start transferring files//start drawing from the top left corner//White says no staining .Spritebatch.begin (); Spritebatch.draw (texture, Vector2.zero,NewRectangle (currentframe.x *framesize.x, Currentframe.y*framesize.y, framesize.x, Framesize.y), Color.White,0, Vector2.zero,1, Spriteeffects.none,0); Spritebatch.end (); Base. Draw (GameTime); } }}
XNA Frame Animation