How to use the matter-js.Body 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 mbchang / dynamics / main.js View on Github external
var Matter = require('matter-js')
var jsonfile = require('jsonfile')
var _ = require('underscore')
require('./demo/js/Examples')

// module aliases
var Engine = Matter.Engine,
    World = Matter.World,
    Bodies = Matter.Bodies,
    Body = Matter.Body,
    Example = Matter.Example;


// some example engine options
var engine_options = {
    positionIterations: 6,
    velocityIterations: 4,
    enableSleeping: false,
    metrics: { extended: true }
};

var env = {}
env.engine = Engine.create(engine_options);


var scenarios = {
github Coder2012 / pixi / spaceshooter / src / js / matterConsts.js View on Github external
import * as Matter from 'matter-js'

// Matter.js module aliases
const consts = {
  Engine: Matter.Engine,
  World: Matter.World,
  Body: Matter.Body,
  Bodies: Matter.Bodies,
  Events: Matter.Events,
  Vector: Matter.Vector,
  Composite: Matter.Composite
}

export default consts
github mbchang / dynamics / hockey.js View on Github external
function () {

    // module aliases
    var Engine = Matter.Engine,
        World = Matter.World,
        Bodies = Matter.Bodies,
        Body = Matter.Body;

    var Hockey = {}

    Hockey.create = function(env) {
        var self = {}; // instance of the Hockey class

        // these should not be mutated
        var params = {show: false,
                      num_obj: 3,
                      cx: 400,  // 640
                      cy: 300,  // 480
                      max_v0: 20,
                      obj_radius: 50 };
        self.params = params;

        // var engine = Engine.create();
github FormidableLabs / react-game-kit / demo / game / character.js View on Github external
jump(body) {
    this.jumpNoise.play();
    this.isJumping = true;
    Matter.Body.applyForce(body, { x: 0, y: 0 }, { x: 0, y: -0.15 });
    Matter.Body.set(body, 'friction', 0.0001);
  };
github JeffreyATW / react-redux-platformer / src / components / floor / Floor.js View on Github external
componentWillReceiveProps(nextProps) {
    if (this.props.rows !== nextProps.rows) {
      const y = STAGE_HEIGHT / 2 + (nextProps.rows * this.state.height) + this.state.height / 2;

      Matter.Body.setPosition(this.body, {x: this.state.x, y});

      this.setState({ y });
    }
  }
}
github FormidableLabs / react-game-kit / demo / game / character.js View on Github external
move(body, x) {
    Matter.Body.setVelocity(body, { x, y: 0 });
  };
github FormidableLabs / react-game-kit / demo / game / character.js View on Github external
jump(body) {
    this.jumpNoise.play();
    this.isJumping = true;
    Matter.Body.applyForce(body, { x: 0, y: 0 }, { x: 0, y: -0.15 });
    Matter.Body.set(body, 'friction', 0.0001);
  };
github mattgrayisok / wulfram-2d / _assets / js / shared / WorldState.js View on Github external
_.each(state.players, function(thisPlayer, playerId){

			if(playerId != exclude){
				var body = Matter.Body.create({ 	
					angle: thisPlayer.angle,
					position: thisPlayer.position,
					vertices: [{ x: -25, y: -25 }, { x: 0, y: 25 }, { x: 25, y: -25 }]
				});
				body.parentPlayer = self.getPlayer(playerId);
				state.bodies.push(body);
			}
		});
	}
github liabru / matter-tools / src / tools / Inspector.js View on Github external
"use strict";

/**
 * A tool for inspecting worlds.
 * @module Inspector
 */

const Inspector = module.exports = {};
const $ = require('jquery');
require('../../node_modules/jstree/dist/jstree.min');
const ToolsCommon = require('./Common');
const Serializer = require('matter-tools').Serializer;
const km = require('keymaster');
const Matter = require('matter-js');
const Body = Matter.Body;
const Bounds = Matter.Bounds;
const Composite = Matter.Composite;
const Common = Matter.Common;
const Events = Matter.Events;
const Mouse = Matter.Mouse;
const Query = Matter.Query;
const Vertices = Matter.Vertices;
const Vector = Matter.Vector;
const MouseConstraint = Matter.MouseConstraint;

var $body;

/**
 * Creates an inspector
 * @function Gui.create
 * @param {engine} engine
github frostney / talks / files / react-game / presentation / components / Ship.js View on Github external
update() {
    const { onUpdate } = this.props;

    if (onUpdate && typeof onUpdate === "function") {
      const onUpdateResult = onUpdate(this.state);

      if (onUpdateResult) {
        this.setState((prevState) => {
          return { ...prevState, ...onUpdateResult };
        });
      }
    }

    if (this.body.body) {
      Matter.Body.setVelocity(this.body.body, { x: this.state.x, y: this.state.y });
    }
  }