C# XNA-Maus Position

Ich habe einige Probleme mit meiner Maus-Koordinaten im XNA - 0 x 0 beliebig nahe (aber nicht in) der linken oberen Ecke meines Bildschirms.

Mir läuft das Spiel in einem Fenstermodus, gerade jetzt, aber die Koordinaten basieren, die aus dem Bildschirm, nicht das Spiel-Fenster (obwohl die XNA-Dokumentation erzählt mir sollte es auch anders sein)

Vielen Dank im Voraus!

Hier der code:

namespace TheGame
{
   class Mousey
   {
      static public Vector2 pos;
      static private Texture2D tex;
      static public MouseState mouseState;
      static public MouseState previousState;

      //static public Mousey()
      //{
      //}

      static public void Update()
      {
         previousState = mouseState;
         mouseState = Mouse.GetState(); //Needed to find the most current mouse states.
         pos.X = mouseState.X; //Change x pos to mouseX
         pos.Y = mouseState.Y; //Change y pos to mouseY
      }

      //Drawing function to be called in the main Draw function.
      static public void LoadContent(ContentManager thecontent)
      {
         tex = thecontent.Load<Texture2D>("mousey");
      }

      static public void Draw(SpriteBatch batch) //SpriteBatch to use.
      {
         batch.Draw(tex, pos, Color.White); //Draw it using the batch.
      }

      static public bool LBP()
      {
          if (mouseState.LeftButton == ButtonState.Pressed && previousState.LeftButton ==                      ButtonState.Released)
          {
              return true; 
          }
          else 
          { 
              return false; 
          }
      }   
   }
}
Dein code funktioniert bei mir einwandfrei. Copypasted es in einem neuen Projekt. Die 0 x 0 ist oben Links, es sei denn, Sie reden über eine 1-pixel-Genauigkeit Sache. Vielleicht ist es das spriteBatch... Einzige, was ich geändert habe.

InformationsquelleAutor Fool Whip | 2011-10-27

Schreibe einen Kommentar