Understanding scrolling
In this section, we will go over how horizontal and vertical scrolling work conceptually and mathematically.
Engage thrusters
In a horizontal scrolling game, the player sprite is always visible, but the non-player sprites can move in and out of the stage. The non-player sprites in the Hunger Run game include the background sprites (such as bricks) and interactive sprites (such as food items). Even when a sprite moves in and out of the stage, it still exists in the game space. In a 2D scrolling game, the game space can be represented as 2D grids, which consists of 2D unit grids as shown in the following screenshot. Each grid unit is the same size as the stage, 480 pixels in length (L) and 360 pixels in width (W).
To keep the player sprite visible while scrolling, we keep the player sprite fixed in the grids but move other sprites horizontally or vertically, depending on the direction of the scrolling. To scroll Marco horizontally by N steps, move the other sprites to...