Utilities in TCJSgame

The utilities in TCJSgame are a collection of helper functions that make it easier to control objects, check states, and perform common operations. They are grouped mainly into two objects: move for movement helpers and state for checking component states.

Move Utilities

The move object contains methods that extend the basic movement system. Examples include teleporting objects, gliding them smoothly, pointing towards targets, and simulating projectile motion.

Examples


// Teleport instantly
move.teleport(player, 200, 100);

// Glide smoothly to a point
move.glideTo(player, 2, 300, 200);

// Point towards target
move.pointTo(player, mouse.x, mouse.y);

// Launch as a projectile
move.project(player, 10, 60, 0.2);
    

State Utilities

The state object provides quick access to component information, such as position, distance from another object, angle, and whether physics is enabled.

Examples


// Get distance between two components
let d = state.distance(player, enemy);

// Get current rectangle [x, y, width, height]
let rect = state.rect(player);

// Check if physics is active
console.log(state.physics(player)); // true or false

// Get angle
console.log(state.Angle(player));
    

Why Use Utilities?

These utility functions save time and keep your code cleaner. Instead of writing repetitive calculations (like distance formulas or manual teleportation), you can call a simple utility. This makes your game logic easier to read and maintain.

Note: Utilities do not run automatically. You must call them from your update() loop or when you want the action to occur.