Move Utils

TCJSgame v3 includes special utilities to make movement more dynamic. Instead of only using speedX and speedY, you can enable angle-based movement and call the moveAngle() method. This lets you move objects in any direction using an angle, making it perfect for spaceships, projectiles, or rotating characters.

To use this system, you must enable changeAngle on the component. Once this is set to true, you can adjust its angle property (in radians) or use anngle for shorthand. Then, call moveAngle() inside your update() loop to apply the movement.

Syntax

component.changeAngle = true;
component.angle = Math.PI / 2; // 90 degrees in radians
component.moveAngle();

Example

const ship = new Component(30, 30, "red", 100, 100, "rect");
ship.changeAngle = true;
ship.speed = 3;
display.add(ship);

function update() {
  if (display.keys[39]) ship.angle += 0.05; // rotate right
  if (display.keys[37]) ship.angle -= 0.05; // rotate left
  
  ship.moveAngle(); // apply angle-based movement
}

Notes