Adding & Updating Components

Once you have created a Component, you must add it to the display. This is done with display.add(component, scene). The second argument is optional and lets you organize objects into different scenes. If you omit it, the component is added to the default scene 0.

After adding a component, TCJSgame automatically draws it every frame. To animate or move components, you must modify their properties inside the update() function. For example, changing x or y makes the object move. Adjusting speedX or speedY lets the engine handle motion automatically.

Syntax

display.add(component, sceneIndex);

Example

const player = new Component(30, 30, "blue", 50, 50, "rect");
display.add(player, 0);

function update() {
  player.x += 2;
}

Notes