Guest User

Untitled

a guest
Feb 7th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.81 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.  
  12. namespace MouseDelayTest
  13. {
  14.     /// <summary>
  15.     /// This is the main type for your game
  16.     /// </summary>
  17.     public class Game1 : Microsoft.Xna.Framework.Game
  18.     {
  19.         Texture2D cursor;
  20.         GraphicsDeviceManager graphics;
  21.         SpriteBatch spriteBatch;
  22.         List<double[]> mouseTicks = new List<double[]>();
  23.         Point cursorPos = new Point();
  24.         public Game1()
  25.         {
  26.             graphics = new GraphicsDeviceManager(this);
  27.             Content.RootDirectory = "Content";
  28.             graphics.PreferredBackBufferWidth = 800;
  29.             graphics.PreferredBackBufferHeight = 600;
  30.         }
  31.  
  32.         /// <summary>
  33.         /// Allows the game to perform any initialization it needs to before starting to run.
  34.         /// This is where it can query for any required services and load any non-graphic
  35.         /// related content.  Calling base.Initialize will enumerate through any components
  36.         /// and initialize them as well.
  37.         /// </summary>
  38.         protected override void Initialize()
  39.         {
  40.             // TODO: Add your initialization logic here
  41.  
  42.             base.Initialize();
  43.         }
  44.  
  45.         /// <summary>
  46.         /// LoadContent will be called once per game and is the place to load
  47.         /// all of your content.
  48.         /// </summary>
  49.         protected override void LoadContent()
  50.         {
  51.             // Create a new SpriteBatch, which can be used to draw textures.
  52.             spriteBatch = new SpriteBatch(GraphicsDevice);
  53.             cursor = Content.Load<Texture2D>("cursor");
  54.  
  55.             // TODO: use this.Content to load your game content here
  56.         }
  57.  
  58.         /// <summary>
  59.         /// UnloadContent will be called once per game and is the place to unload
  60.         /// all content.
  61.         /// </summary>
  62.         protected override void UnloadContent()
  63.         {
  64.             // TODO: Unload any non ContentManager content here
  65.         }
  66.  
  67.         /// <summary>
  68.         /// Allows the game to run logic such as updating the world,
  69.         /// checking for collisions, gathering input, and playing audio.
  70.         /// </summary>
  71.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  72.         protected override void Update(GameTime gameTime)
  73.         {
  74.             // Allows the game to exit
  75.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  76.                 this.Exit();
  77.             MouseState m = Mouse.GetState();
  78.             // TODO: Add your update logic here
  79.             double t = gameTime.TotalGameTime.TotalMilliseconds;
  80.             mouseTicks.Add(new double[3] {m.X,m.Y,t});
  81.             while (t - mouseTicks[0][2] >= 32)
  82.             {
  83.                 cursorPos.X = (int)mouseTicks[0][0];
  84.                 cursorPos.Y = (int)mouseTicks[0][1];
  85.                 mouseTicks.RemoveAt(0);
  86.             }
  87.             base.Update(gameTime);
  88.         }
  89.  
  90.         /// <summary>
  91.         /// This is called when the game should draw itself.
  92.         /// </summary>
  93.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  94.         protected override void Draw(GameTime gameTime)
  95.         {
  96.             GraphicsDevice.Clear(Color.White);
  97.             spriteBatch.Begin();
  98.             spriteBatch.Draw(cursor, new Rectangle(cursorPos.X, cursorPos.Y, cursor.Width, cursor.Height), Color.White);
  99.             spriteBatch.End();
  100.             // TODO: Add your drawing code here
  101.  
  102.             base.Draw(gameTime);
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment