I am making a 15 piece puzzle game and having difficulty making my sprite move one tile at a time, when i initially press the left key the sprite moves once, but after that the sprite moves multiple tiles after i press the keys again, instead of moving one tile like it should. Eventually this also messes with the sprites and some of them disappear. The code that i use to determine movement is:
if (positionx16 - positionx1 == 200 && positiony16 == positiony1)
{
canswapleft1 = true;
}
if (oldState.IsKeyUp(Keys.Left) && newState.IsKeyDown(Keys.Left))
{
if (positionx16 > 0 && canswapleft1 == true)
{
positionx16 += -widthoftile;
positionx1 += widthoftile;
canswapleft1 = false;
}
}
The positionx16 is the X position of the player controlled tile, and the positionx1 referes to the X position of the 1st tile, this was repeated for each tile.