Hyluss

[MonoGame] AnimatedSpriteGame

Oct 23rd, 2018
286
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13.  
  14. namespace TextureAtlas
  15. {
  16.     public class Game1 : Microsoft.Xna.Framework.Game
  17.     {
  18.         GraphicsDeviceManager graphics;
  19.         SpriteBatch spriteBatch;
  20.         private AnimatedSprite animatedSprite;
  21.  
  22.         public Game1()
  23.         {
  24.             graphics = new GraphicsDeviceManager(this);
  25.             Content.RootDirectory = "Content";
  26.         }
  27.  
  28.         protected override void Initialize()
  29.         {
  30.             base.Initialize();
  31.         }
  32.  
  33.         protected override void LoadContent()
  34.         {
  35.             spriteBatch = new SpriteBatch(GraphicsDevice);
  36.  
  37.             Texture2D texture = Content.Load<Texture2D>("SmileyWalk");
  38.             animatedSprite = new AnimatedSprite(texture, 4, 4);
  39.         }
  40.  
  41.         protected override void UnloadContent()
  42.         {
  43.         }
  44.  
  45.         protected override void Update(GameTime gameTime)
  46.         {
  47.             // Allows the game to exit
  48.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  49.                 this.Exit();
  50.  
  51.             animatedSprite.Update();
  52.  
  53.             base.Update(gameTime);
  54.         }
  55.  
  56.         protected override void Draw(GameTime gameTime)
  57.         {
  58.             GraphicsDevice.Clear(Color.CornflowerBlue);
  59.  
  60.             animatedSprite.Draw(spriteBatch, new Vector2(400, 200));
  61.  
  62.             base.Draw(gameTime);
  63.         }
  64.     }
  65. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment