I've got a player Class which can walk to a certain point on the screen when left mouse is pressed:
if (mState.LeftButton == ButtonState.Released && oldMouseState.LeftButton == ButtonState.Pressed)
{
if (mState.X > CurrentPosition.X)
{
CurrentDirection = Direction.Right;
}
else if (mState.X < CurrentPosition.X)
{
CurrentDirection = Direction.Left;
}
CurrentDestination = new Vector2(mState.X, mState.Y);
CurrentState = PlayerState.Moving;
reachedDestination = false;
}
Now I have several Characters on screen. If I want to select one of them I also do a left click, which sets the character to selected.
if (mState.LeftButton == ButtonState.Released && oldMSstate.LeftButton == ButtonState.Pressed)
{
if (player1.BoundingBox.Contains(new Point(mState.X, mState.Y)))
{
if (!player1.Selected)
{
player1.Selected = true;
player2.Selected = false;
}
}
if (player2.BoundingBox.Contains(new Point(mState.X, mState.Y)))
{
if (!player2.Selected)
{
player2.Selected = true;
player1.Selected = false;
}
}
}
The problem is that as soon as one of the characters is selected it also performs the moving animation. This is beacuse for the trigger is the same for both moving to destination and selecting.
Do you know any way to avoid this behaviour and still keep using the left click for both?
Thanks in advance!
mState
refer to - player1 or player2? \$\endgroup\$