I'm doing a tile based 2d rpg in pygame. The problem I'm working on right now is character movement... I am already able to create a map by using multidimensional arrays and a 'camera' follows the player. My problem is now the collision detection... The player should only move one tile at the time so I can easily get his position in tile coordinates and check if he's collided. But I don't know how to do that! At the moment, if a key is pressed, the player moves four pixels in a direction every frame. But that makes tile based collision detection nearly impossible. The player has the size of one tile and yeah, my question is, how can I make the player move only one tile (but NOT every frame since then he would move 32 pixels every single frame.) I know this question was asked before : Pygame Tile Based Character movement speed but this wouldn't work for me, because you had to press the key EVERY TIME you want to move one tile. I use booleans so the player moves as long as the key is pressed.
To solve your problem check every frame if the button is pressed, if so increment the position.
To have the snapping effect you need to round down your position to tileX position like with this code
If your player can move backwards just decrement the position if the other button is pressed.