How to use the matter-js.World 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 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 lepunk / react-native-videos / FlappyBird / App.js View on Github external
Constants.MAX_HEIGHT - 25,
            Constants.MAX_WIDTH + 4,
            50,
            { isStatic: true }
        );

        let floor2 = Matter.Bodies.rectangle(
            Constants.MAX_WIDTH + (Constants.MAX_WIDTH / 2),
            Constants.MAX_HEIGHT - 25,
            Constants.MAX_WIDTH + 4,
            50,
            { isStatic: true }
        );


        Matter.World.add(world, [bird, floor1, floor2]);
        Matter.Events.on(engine, 'collisionStart', (event) => {
            var pairs = event.pairs;

            this.gameEngine.dispatch({ type: "game-over"});

        });

        return {
            physics: { engine: engine, world: world },
            floor1: { body: floor1, renderer: Floor },
            floor2: { body: floor2, renderer: Floor },
            bird: { body: bird, pose: 1, renderer: Bird},
        }
    }
github FormidableLabs / react-game-kit / src / components / world.js View on Github external
constructor(props) {
    super(props);

    this.loopID = null;
    this.lastTime = null;

    const world = Matter.World.create({ gravity: props.gravity });

    this.engine = Engine.create({
      world,
    });

    this.loop = this.loop.bind(this);
  }
github lepunk / react-native-videos / FlappyBird / Physics.js View on Github external
x,
        Constants.MAX_HEIGHT - 50 - pipe2Height - (pipeTopHeight / 2),
        pipeTopWidth,
        pipeTopHeight,
        { isStatic: true}
    );

    let pipe2 = Matter.Bodies.rectangle(
        x,
        Constants.MAX_HEIGHT - 50 - (pipe2Height / 2),
        Constants.PIPE_WIDTH,
        pipe2Height,
        { isStatic: true}
    );

    Matter.World.add(world, [pipe1, pipe1Top, pipe2, pipe2Top]);

    entities["pipe" + (pipes + 1)] = {
        body: pipe1, renderer: Pipe, scored: false
    }

    entities["pipe" + (pipes + 2)] = {
        body: pipe2, renderer: Pipe, scored: false
    }

    entities["pipe" + (pipes + 1) + "Top"] = {
        body: pipe1Top, renderer: PipeTop, scored: false
    }

    entities["pipe" + (pipes + 2) + "Top"] = {
        body: pipe2Top, renderer: PipeTop, scored: false
    }
github bberak / react-native-game-engine-handbook / app / physics / rigid-bodies / index.js View on Github external
const engine = Matter.Engine.create({ enableSleeping: false });
    const world = engine.world;
    const body = Matter.Bodies.rectangle(width / 2, -1000, boxSize, boxSize, { frictionAir: 0.021 });
    const floor = Matter.Bodies.rectangle(width / 2, height - boxSize / 2, width, boxSize, { isStatic: true });
    const constraint = Matter.Constraint.create({
      label: "Drag Constraint",
      pointA: { x: 0, y: 0 },
      pointB: { x: 0, y: 0 },
      length: 0.01,
      stiffness: 0.1,
      angularStiffness: 1
    });

    Matter.World.add(world, [body, floor]);
    Matter.World.addConstraint(world, constraint);

    return (
      

        

      
    );
  }
github bberak / react-native-game-engine / app / physics-libraries / rigid-bodies / systems.js View on Github external
touches.filter(t => t.type === "press").forEach(t => {
	    const body = Matter.Bodies.rectangle(t.event.pageX, t.event.pageY, 50, 50, { frictionAir: 0.021 });
    	Matter.World.add(world, [body]);

		state[++boxIds] = {
			body: body,
			size: [50, 50],
			renderable: Box
		};
	});
github RoganMurley / hitagi.js / src / systems / matterPhysicsSystem.js View on Github external
body: function (entity) {
                Matter.World.remove(engine.world, bodies[entity.uid]);
                delete bodies[entity.uid];
            }
        };
github RoganMurley / hitagi.js / src / systems / matterPhysicsSystem.js View on Github external
body.force = entity.c.body.force;
                proxy(entity.c.body, 'force', body, 'force');

                proxy(entity.c.body, 'density', body, 'density');


                body.position.x = entity.c.body.x;
                proxy(entity.c.body, 'x', body.position, 'x');

                body.position.y = entity.c.body.y;
                proxy(entity.c.body, 'y', body.position, 'y');

                //proxy(entity.c, 'velocity', body, 'velocity');

                Matter.World.add(engine.world, body);
                bodies[entity.uid] = body;
            }
        };
github liabru / matter-tools / src / tools / Gui.js View on Github external
/**
 * A tool for modifying the properties of an engine and renderer.
 * @module Gui
 */

var Gui = module.exports = {};

const dat = require('../../node_modules/dat.gui/build/dat.gui.min');
const ToolsCommon = require('./Common');
const Serializer = require('matter-tools').Serializer;
const Matter = require('matter-js');
const Engine = Matter.Engine;
const Detector = Matter.Detector;
const Grid = Matter.Grid;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Events = Matter.Events;
const Composite = Matter.Composite;

/**
 * Creates a Gui
 * @function Gui.create
 * @param {engine} [engine]
 * @param {runner} [runner]
 * @param {render} [render]
 * @return {gui} The created gui instance
 */
Gui.create = function(engine, runner, render) {
  dat.GUI.TEXT_CLOSED = '▲';
  dat.GUI.TEXT_OPEN = '▼';
github FormidableLabs / react-game-kit / src / native / components / world.js View on Github external
constructor(props) {
    super(props);

    this.loopID = null;
    this.lastTime = null;

    const world = Matter.World.create({ gravity: props.gravity });

    this.engine = Engine.create({
      world,
    });

    this.loop = this.loop.bind(this);
  }