How to use the matter-js.Engine.update function in matter-js

To help you get started, we’ve selected a few matter-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plinko-team / plinko / src / server / serverEngine.js View on Github external
startGame() {
    this.gameIsRunning = true;

    this.nextTimestep = this.nextTimestep || Date.now();

    while (Date.now() > this.nextTimestep) {
      this.frame++

      !this.inputBuffer.isEmpty() && this.processInputBuffer();

      Engine.update(this.engine, TIMESTEP);

      if (!this.targetScoreInterval) { this.reduceTargetScoreInterval() }

      if (!this.winner && this.gameIsOver()) {
        this.winner = true;
        clearInterval(this.targetScoreInterval);
        this.endRound();
      }

      let snapshot = this.generateSnapshot(this.chips, this.pegs, this.score,
                                           this.winner, this.targetScore);

      this.broadcastSnapshot(snapshot);

      this.nextTimestep += TIMESTEP;
    }
github FormidableLabs / react-game-kit / src / components / world.js View on Github external
loop() {
    const currTime = 0.001 * Date.now();
    Engine.update(
      this.engine,
      1000 / 60,
      this.lastTime ? currTime / this.lastTime : 1
    );
    this.lastTime = currTime;
  }
}
github krzema12 / hypergravity / src / GravityAnimationModel.js View on Github external
getElementsForNextFrame(deltaSeconds) {
    PhysicsEngine.update(this._physicsEngine, deltaSeconds);

    let elementsToReturn = [];

    for (let physicsBody of this._physicsEngine.world.bodies) {
      if (physicsBody.isStatic) {
        continue;
      }

      physicsBody.element.x = physicsBody.position.x;
      physicsBody.element.y = physicsBody.position.y;
      physicsBody.element.rotation = physicsBody.angle;
      elementsToReturn.push(physicsBody.element);
    }

    return elementsToReturn;
  }
github FormidableLabs / react-game-kit / src / native / components / world.js View on Github external
loop() {
    const currTime = 0.001 * Date.now();
    Engine.update(
      this.engine,
      1000 / 60,
      this.lastTime ? currTime / this.lastTime : 1,
    );
    this.lastTime = currTime;
  }
}
github vibertthio / runn / src / renderer / physic.js View on Github external
draw(ctx) {
    this.progress = this.renderer.progress;
    this.progressPosition = this.renderer.width * 0.3;
    const { chord } = this.renderer;

    Engine.update(this.engine);
    const bodies = Composite.allBodies(this.engine.world);

    if (this.avatar) {
      this.avatar.update();
    }

    if (chord) {
      this.avatarChord.update();
    }

    ctx.save();

    ctx.save();
    if (this.checkBand()) {
      ctx.fillStyle = palette[6];
    } else {
github plinko-team / plinko / src / client / gameLoop.js View on Github external
this.loop = setInterval(() => {
      while (Date.now() > this.nextTimestep) {
        Engine.update(this.engine, TIMESTEP);
        this.nextTimestep += TIMESTEP;
      }

      this.renderer.render(this.stage);
    }, 0)
  }
github cyclegtx / colyseus-iog-state-sync / IOGStateSync / GameRoom.ts View on Github external
update() {
        for (let k in this.state.entities) {
            this.state.entities[k].update(this.clock.deltaTime);
        }
        Engine.update(this.engine, this.clock.deltaTime);
    }
github plinko-team / plinko / src / shared / game.js View on Github external
this.loop = setInterval(() => {
      while (Date.now() > this.nextTimestep) {

        Engine.update(this.engine, TIMESTEP);
        this.nextTimestep += TIMESTEP;

      }

      let interpolation = (Date.now() + TIMESTEP - this.nextTimestep)
                        / TIMESTEP;

      this.env === 'client' && this.chips.forEach(chip => {
        chip.sprite.destination = chip.body.position;
        chip.sprite.begin = chip.sprite.position;
        let incrementX = chip.sprite.destination.x - chip.sprite.begin.x;
        let incrementY = chip.sprite.destination.y - chip.sprite.begin.y;

        chip.sprite.position.x += incrementX * interpolation;
        chip.sprite.position.y += incrementY * interpolation;
        chip.sprite.rotation = chip.body.angle;