How to use the matter-js.Events.on 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 vibertthio / runn / src / renderer / physic.js View on Github external
for (let i = 0; i < pairs.length; i++) {
        const pair = pairs[i];

        if (pair.bodyA.label === 'avatar' || pair.bodyB.label === 'avatar') {
          // console.log('avatar collision start');
          this.onBlock = (pair.bodyA.label === 'avatar') ? pair.bodyB : pair.bodyA;
        }

        if (pair.bodyA.label === 'avatarChord' || pair.bodyB.label === 'avatarChord') {
          // console.log('avatar collision start');
          this.onBlockChord = (pair.bodyA.label === 'avatarChord') ? pair.bodyB : pair.bodyA;
        }
      }
    });

    Events.on(this.engine, 'collisionEnd', e => {
      const pairs = e.pairs;
      for (let i = 0; i < pairs.length; i++) {
        const pair = pairs[i];
        if (pair.bodyA.label === 'avatar' || pair.bodyB.label === 'avatar') {
          // console.log('avatar collision start');
          this.onBlock = null;
        }

        if (pair.bodyA.label === 'avatarChord' || pair.bodyB.label === 'avatarChord') {
          // console.log('avatar collision start');
          this.onBlockChord = null;
        }
      }
    });

  }
github vibertthio / runn / src / renderer / physic.js View on Github external
initCollisionEvents() {
    Events.on(this.engine, 'collisionStart', e => {
      const pairs = e.pairs;
      for (let i = 0; i < pairs.length; i++) {
        const pair = pairs[i];

        if (pair.bodyA.label === 'avatar' || pair.bodyB.label === 'avatar') {
          // console.log('avatar collision start');
          this.onBlock = (pair.bodyA.label === 'avatar') ? pair.bodyB : pair.bodyA;
        }

        if (pair.bodyA.label === 'avatarChord' || pair.bodyB.label === 'avatarChord') {
          // console.log('avatar collision start');
          this.onBlockChord = (pair.bodyA.label === 'avatarChord') ? pair.bodyB : pair.bodyA;
        }
      }
    });
github plinko-team / plinko / src / server / serverEngine.js View on Github external
registerPhysicsEvents() {
    // Collision Events
    Events.on(this.engine, 'collisionStart', this.onCollisionStart);
  }
github plinko-team / plinko / src / shared / game.js View on Github external
registerPhysicsEvents() {
    // Collision Events
    Events.on(this.engine, 'collisionStart', this.onCollisionStart);
  }
github FormidableLabs / react-game-kit / src / native / components / world.js View on Github external
componentDidMount() {
    this.loopID = this.context.loop.subscribe(this.loop);
    this.props.onInit(this.engine);
    Events.on(this.engine, 'afterUpdate', this.props.onUpdate);
    Events.on(this.engine, 'collisionStart', this.props.onCollision);
  }
github FormidableLabs / react-game-kit / src / components / world.js View on Github external
componentDidMount() {
    this.loopID = this.context.loop.subscribe(this.loop);
    this.props.onInit(this.engine);
    Events.on(this.engine, 'afterUpdate', this.props.onUpdate);
    Events.on(this.engine, 'collisionStart', this.props.onCollision);
  }
github cyclegtx / colyseus-iog-state-sync / IOGStateSync / GameRoom.ts View on Github external
onInit (options: any) { 
        this.state = new GameState();
        this.setState(this.state);
        this.engine = Engine.create();
        this.engine.world.gravity.scale = 0;
        this.createWalls();
        
        Events.on(this.engine, "collisionStart", this.onCollisionStart.bind(this));
        Events.on(this.engine, "collisionEnd", this.onCollisionStart.bind(this));

        this.setSimulationInterval(this.update.bind(this));
        this.clock.setInterval(this.broadcastAllEntityIds.bind(this), 3000);
    }