在构造函数中我做了:
mouseState = Mouse.GetState();
var mousePosition = new Point(mouseState.X, mouseState.Y);
然后在我创建的输入法中添加:
private void ProcessInput(float amount)
{
Vector3 moveVector = new Vector3(0, 0, 0);
KeyboardState keyState = Keyboard.GetState();
if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.W))
moveVector += new Vector3(0, 0, -1);
if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.S))
moveVector += new Vector3(0, 0, 1);
if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D))
moveVector += new Vector3(1, 0, 0);
if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A))
moveVector += new Vector3(-1, 0, 0);
if (keyState.IsKeyDown(Keys.Q))
moveVector += new Vector3(0, 1, 0);
if (keyState.IsKeyDown(Keys.Z))
moveVector += new Vector3(0, -1, 0);
if (keyState.IsKeyDown(Keys.Escape))
{
this.graphics.PreferredBackBufferWidth = 800;
this.graphics.PreferredBackBufferHeight = 600;
this.graphics.IsFullScreen = false;
this.graphics.ApplyChanges();
}
if (mouseState.LeftButton == ButtonState.Pressed)
{
this.graphics.PreferredBackBufferWidth = 1920;
this.graphics.PreferredBackBufferHeight = 1080;
this.graphics.IsFullScreen = true;
this.graphics.ApplyChanges();
}
AddToCameraPosition(moveVector * amount);
}
我补充说:
if (mouseState.LeftButton == ButtonState.Pressed)
{
this.graphics.PreferredBackBufferWidth = 1920;
this.graphics.PreferredBackBufferHeight = 1080;
this.graphics.IsFullScreen = true;
this.graphics.ApplyChanges();
}
我使用了一个断点,当单击鼠标左键时它什么也不做。它永远不会进入这个if
块。它正在到达if
但从未进入它。
那么我该如何让它工作呢?以及如何使鼠标左键双击而不是单击?