Displaying a Level/Map

Published — Edited

This guide assumes that you have read up to Repainting a Screen.

In Roguelike & Roguelite games, the player is often shown a top-down view of a 2D level or map. Although there are countless ways to design and display levels and maps, there are only two obvious choices for displaying them with VTerminal.

On its own, a VPanel cannot display partial tiles. If you create one and tell it to display a grid of 32x32 tiles, it will display exactly that. To display partial tiles, you must embed a VPanel within a JScrollPane and change the unit increment for horizontal and vertical scrolling.

The deciding factor between using a VPanel on its own, or embedded within a JScrollPane, is whether you plan to implement effects such as screen shaking and tracking.

Creating a Map

Before testing our display options, we first need something to test them on. The following class describes a 2D map of tiles, each represented by a capital character, and a camera view determined by two offset values.

Displaying on a VPanel

In this example we can move our camera around the map using the arrow keys. The camera can only be moved by one tile at a time.

Displaying on a JScrollPane

As with the previous example, we can move our camera around the map using the arrow keys. The map and camera now appear to move independently, the camera moves in pixel increments rather than tile increments, and the camera slowly tracks/follows the direction of movement.