gpt4 book ai didi

C# XNA 鼠标位置

转载 作者:太空狗 更新时间:2023-10-29 22:54:10 25 4
gpt4 key购买 nike

我在 XNA 中的鼠标坐标有一些问题 - 0x0 任意靠近(但不在)我屏幕的左上角。

我现在正在窗口模式下运行游戏,但坐标是基于屏幕的,而不是游戏窗口(尽管 XNA 文档告诉我它应该不是这样)

提前致谢!

代码如下:

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;
}
}
}
}

最佳答案

在 game.cs 中:

//sets the windows mouse handle to client bounds handle

Mouse.WindowHandle = Window.Handle;

关于C# XNA 鼠标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7911124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com