TILE.CS MAIN XNA FILE #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; #endregion namespace Tiles { /// /// This is the main type for your game /// public class Tiles : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; Tile grass; Tile cloud; AnimatedSprite plasma; public SpriteBatch spriteBatch; public Tiles() { //Determines proper screen size graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 800; graphics.PreferredBackBufferHeight = 600; content = new ContentManager(Services); } /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() { //Sets properties for the sprites spriteBatch = new SpriteBatch(graphics.GraphicsDevice); grass = new Tile(); grass.Position = Vector2.Zero; grass.Color = Color.White; grass.Layer = .8f; cloud = new Tile(); cloud.Position = Vector2.Zero; cloud.Color = Color.White; cloud.Layer = 1.0f; plasma = new AnimatedSprite(120, graphics); for (int i = 1; i < 120; i++) { plasma.textures.Add(content.Load(@"Textures/plasmaSplash/000"+i)); } plasma.Layer = 1.0f; plasma.Color = Color.White; base.Initialize(); } /// /// Load your graphics content. If loadAllContent is true, you should /// load content from both ResourceManagementMode pools. Otherwise, just /// load ResourceManagementMode.Manual content. /// /// Which type of content to load. protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { //Loads the sprites and calls the initialize grass.Texture = content.Load(@"Textures/grass"); cloud.Texture = content.Load(@"Textures/cloud"); grass.Initialize(); cloud.Initialize(); } // TODO: Load any ResourceManagementMode.Manual content } /// /// Unload your graphics content. If unloadAllContent is true, you should /// unload content from both ResourceManagementMode pools. Otherwise, just /// unload ResourceManagementMode.Manual content. Manual content will get /// Disposed by the GraphicsDevice during a Reset. /// /// Which type of content to unload. protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { // TODO: Unload any ResourceManagementMode.Automatic content content.Unload(); } // TODO: Unload any ResourceManagementMode.Manual content } /// /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input and playing audio. /// /// Provides a snapshot of timing values. protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); //TODO: Add update code. base.Update(gameTime); } /// /// This is called when the game should draw itself. /// /// Provides a snapshot of timing values. protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); // grass.Draw(spriteBatch); //cloud.Draw(spriteBatch); plasma.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); } } } -------------------- ANIMATEDSPRITE.CS using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace Tiles { class AnimatedSprite { public AnimatedSprite(int frameCount, GraphicsDeviceManager graphics) { frames = frameCount; Graphics = graphics; } private GraphicsDeviceManager Graphics; private Texture2D texture; private Color color; public List textures = new List(); private Vector2 position; private float layer; private int frames; #region Properties public Texture2D Texture { get { return texture; } set { texture = value; } } public Vector2 Position { get { return position; } set { position = value; } } public Color Color { get { return color; } set { color = value; } } public float Layer { get { return layer; } set { layer = value; } } #endregion public void Draw(SpriteBatch spriteBatch) { foreach (Texture2D sprite in textures) { Graphics.GraphicsDevice.Clear(Color.Black); Rectangle sourceRectangle = new Rectangle(0, 0, 320, 240); spriteBatch.Draw(sprite, new Vector2(50,50), sourceRectangle, color, 0.0f, new Vector2(0, 0), 1.0f, SpriteEffects.None, layer); } } } }