How to Get a Character Moving in a Tile-Based Game

How do we enable movement for a character in a tile-based game?

Final answer: To move a character in a tile-based game, the character's x and y coordinates within the Character class are changed, reflecting their new position on the tile grid, akin to changing position on a city grid. Adjusting the window size or modifying the Tile class does not cause movement. The tiles themselves generally remain in a fixed position, forming the reference frame for the character's movement.

Explanation: To get the character moving in a tile-based game, we typically change the character's x and y coordinates; this is similar to how displacement works in the physical world. In a city, if a woman walks east and then north, each movement is perpendicular, and changing one coordinate doesn't affect the other. Similarly, in a game, moving the character involves altering their position on the game's grid by updating their x (horizontal) and y (vertical) coordinates within the Character class, not the Tile class. The tiles themselves usually stay stationary, serving only as the stage upon which the character moves.

Therefore, the correct answer is a) Change the character's x and y coordinates; update Tile's position, with the caveat that 'updating Tile's position' likely means updating the character's position relative to the tiles rather than the tiles themselves.

Position in a game is relative to a frame of reference, just as in the real world. If we consider the tile grid as our reference frame, moving a character requires a change in the character's position relative to this grid. In contrast, if we adjust the window size or modify the Tile class without changing the character's coordinates, the character will not appear to move within the game world.

Therefore, to simulate movement, developers will primarily be concerned with the Character class's x and y properties to reflect the character's new position after an input is received, which could be from a keyboard or controller, for example.

← Let s dive into the world of social engineering attacks Understanding different types of entity data →