1 min to read
鍵盤、滑鼠輸入
只是筆記,搬運自:
MonoGame 笔记 - KeyboardState 键盘输入 - 知乎
MonoGame 笔记 - MouseState 滑鼠输入 - 知乎
▌KeyboardState 鍵盤輸入
KeyboardState kb = Keyboard.GetState();
if (kb.IsKeyDown(Keys.Left)){
// something here
} else if (kb.IsKeyDown(Keys.Right)){
// something here
} else if (kb.IsKeyDown(Keys.Up)){
// something here
} else if (kb.IsKeyDown(Keys.Down)){
// something here
}
▌MouseState 滑鼠輸入
MouseState ms = Mouse.GetState();
if (ms.LeftButton == ButtonState.Pressed){
// something here
}
Don’t repeat to loop call (mouse down):
ButtonState lastButtonState = ButtonState.Released;
MouseState ms = Mouse.GetState();
if (ms.LeftButton == ButtonState.Pressed && ms.LeftButton != lastButtonState){
// something here
}
lastButtonState = ms.LeftButton;