Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Mouse Movement Blocks Keyboard Input

$
0
0

@Conroy wrote:

On Windows 10 UWP, using Monogame 3.6 and Visual Studios 2017, I have a 2d game where the player can move left and right with:


currentKeyboardState = Keyboard.GetState();
currentMouseState = Mouse.GetState(); //used later, if player presses
//LMB then it fires projectile in direction of cursor
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;//time since the last frame is //used to keep player movement smooth, in case of framerate drop
//
//player movement
//
if (currentKeyboardState.IsKeyDown(Keys.A))//move player left
{
//hasten framerate for movement animation
millisecondsPerFrame = 200;
currentAnimationFrame = "PlayerLeft";
player_X_Pos -= playerMoveSpeed * elapsed;//move player left, multiply by elapsed
camPos.X = player_X_Pos;// move camera with player
cam.Move(camPos);
}
else if (currentKeyboardState.IsKeyDown(Keys.D))//move player right
{
millisecondsPerFrame = 200;
currentAnimationFrame = "PlayerRight";
player_X_Pos += playerMoveSpeed * elapsed;
camPos.X = player_X_Pos;
cam.Move(camPos);
}
else if (currentKeyboardState.IsKeyDown(Keys.W))//move player up(for ladders)
{
player_Y_Pos -= playerMoveSpeed;
camPos.Y = player_Y_Pos;
cam.Move(camPos);
}
else if (currentKeyboardState.IsKeyDown(Keys.S))//move player down(for ladders)
{
if (floorRect.Top > PlayerRect.Bottom)//dont let player move through floor
{
player_Y_Pos += playerMoveSpeed;
camPos.Y = player_Y_Pos;
cam.Move(camPos);
}
}

This is inside the update method and works fine. However, when I move the character left or right and then begin to move the mouse, the character continues to move in that direction, as long as the mouse is still moving. Does anyone know what is causing this issue?

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles