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
- Always add a component to the display or it won’t be rendered.
- Use scenes to manage menus, levels, or game states.
- You can hide or show components later without removing them.