Acceleration

Acceleration is the rate of change of speed over time. In TCJSgame, you can simulate acceleration by gradually increasing or decreasing speedX and speedY each frame. This gives smoother motion than instantly setting a new speed, which feels more natural for cars, planes, or physics-based movement.

While there isn’t a dedicated acceleration property, you can implement it easily inside your update() function. For example, pressing the right arrow key could increase speedX little by little until a maximum speed is reached.

Example

if (display.keys[39]) {
  player.speedX += 0.1; // accelerate right
  if (player.speedX > 5) player.speedX = 5; // cap speed
} else {
  player.speedX *= 0.9; // friction
}

Notes