1
抵消我這裏得到鼠標的位置,並繪製它的一些簡單的代碼:XNA鼠標位置在很大程度上是由實際位置
class Pointer
{
MouseState currPointerState;
Vector2 currPointerPos;
public Pointer()
{
}
public void Update()
{
currPointerState = Mouse.GetState();
currPointerPos.X = currPointerState.X;
currPointerPos.Y = currPointerState.Y;
}
public void Draw(SpriteBatch spriteBatch, Texture2D pointerTexture)
{
spriteBatch.Draw(pointerTexture, currPointerPos, Color.White);
}
}
然後在我的遊戲主文件:
protected override void Update(GameTime gameTime)
{
pointer.Update();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
pointer.Draw(spriteBatch, pointerTexture);
menuManager.Draw(spriteBatch, menu_bar);
spriteBatch.End();
base.Draw(gameTime);
}
遊戲現在在一個窗口中運行,但鼠標右邊約500像素,遠低於實際鼠標位置100像素。
發生這種情況後,我加入以下代碼:(菜單拉絲級)
enum MenuState
{
mainMenu,
playing,
options
};
class MenuManager : Game1
{
MenuState menuState = MenuState.mainMenu;
Vector2 button1 = Vector2.Zero;
public void Draw(SpriteBatch spriteBatch, Texture2D menuBar)
{
switch (menuState)
{
case MenuState.mainMenu:
spriteBatch.Draw(menuBar, button1, Color.White);
break;
}
}
}
}
任何想法,爲什麼鼠標的位置可能已經改變了嗎?