Display Class

The Display class is the foundation of every TCJSgame project. It represents the canvas and manages the game loop. You use it to start the game, clear the screen, and switch between different scenes. The display is responsible for drawing all components that belong to the active scene, making it the heart of rendering. Without it, nothing would appear on the screen.

When you create a new Display instance, you must call start(width, height) to initialize the canvas. You can then use other methods such as clear(), stop(), or fullScreen(). In v3, gradients are supported with lgradient() and rgradient(), making it easy to create visually interesting backgrounds without additional images.

Syntax

const display = new Display();
display.start(800, 600);

Methods

Example

const display = new Display();
display.start(600, 400);
display.lgradient("right", "blue", "lightblue");

Notes