I don’t really agree with the fact of storing the player position x and y as pixel values. In this example, the rectWidth and rectHeight variables are not going to change because they are computed inside the setup() function.
Nevertheless here are few reasons why :
-
What if you can resize the window like this? : setResizable() / Reference / Processing.org
Then the player is not going to react to it… -
What if you want to display the grid smaller, you need to change the tile size so the player is no longer aligned
-
Also what if you change the number of rows and cols at runtime?