How to change speed of update function

I have a sprite that moves along a loop of sprites. When the Up button is pushed, I call

n—;
sprite.x=loop[n].x;
sprite.y=loop[n].y;

It works great, and the sprite moves along the squares smoothly. However, it moves at a fixed speed, and I cannot figure out how to change it.

I have tried this.matter.world.engine.timeStep=2 but instead of changing the sprites speed, it slows down everything else in the game.

Is there a way to change the speed of the update function for a particular sprite, so that I can slow down n—?

Maybe with another variable like:

  create() {
    this.updateIterations = 0;
  }
  update() { 
    this.updateIterations++;
    if (this.updateIterations % 2 === 0) { // once every 2 updates
      n—-;
      sprite.x=loop[n].x;
      sprite.y=loop[n].y;
    }
  }
1 Like

Thanks that works great!