How to use the matter-js.Engine 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 bastarder / vue-endless-h5-game / src / js / fight-wall.js View on Github external
// 木偶人对战画面, 效率太低, 废弃;
let Matter = require('matter-js');
 var Engine = Matter.Engine,
     Render = Matter.Render,
     Runner = Matter.Runner,
     Body = Matter.Body,
     Constraint = Matter.Constraint,
     MouseConstraint = Matter.MouseConstraint,
     Mouse = Matter.Mouse,
     World = Matter.World,
     Bodies = Matter.Bodies,
     Composites = Matter.Composites,
     Composite = Matter.Composite,
     Events = Matter.Events;

Composites.Person = function(x, y, ){
  let group = Body.nextGroup(true),
      Person = Composite.create({ label: 'Person'}),
      radius = 2;
github bberak / react-native-game-engine / app / physics-libraries / rigid-bodies / systems.js View on Github external
const Physics = (state, { touches, time }) => {
	let engineId = Object.keys(state).find(key => state[key].engine);
	let engine = state[engineId].engine;
	console.log(time)
	Matter.Engine.update(engine, time.delta);

	return state;
};
github lepunk / react-native-videos / FlappyBird / App.js View on Github external
setupWorld = () => {
        let engine = Matter.Engine.create({ enableSleeping: false });
        let world = engine.world;
        world.gravity.y = 0.0;

        let bird = Matter.Bodies.rectangle( Constants.MAX_WIDTH / 2, Constants.MAX_HEIGHT / 2, Constants.BIRD_WIDTH, Constants.BIRD_HEIGHT);

        let floor1 = Matter.Bodies.rectangle(
            Constants.MAX_WIDTH / 2,
            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,
github bberak / react-native-game-engine-handbook / app / physics / rigid-bodies / systems.js View on Github external
const Physics = (state, { touches, time }) => {
	let engine = state["physics"].engine;

	Matter.Engine.update(engine, time.delta);

	return state;
};
github RoganMurley / hitagi.js / src / systems / matterPhysicsSystem.js View on Github external
this.tickStart = function () {
            var event = {
                timestamp: engine.timing.timestamp
            };

            Matter.Events.on(engine, "beforeRender",  event);
            Matter.Events.on(engine, "beforeTick",  event);
            Matter.Events.on(engine, "tick",  event);

            Matter.Engine.update(engine, 1000/60);

            Matter.Events.on(engine, "afterTick",  event);
            Matter.Events.on(engine, "afterRender",  event);
        };
github liabru / matter-tools / src / tools / Gui.js View on Github external
"use strict";

/**
 * 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) {
github plinko-team / plinko / lib / client / engine.js View on Github external
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _matterJs = require('matter-js');

var engine = _matterJs.Engine.create();
exports.default = engine;
//# sourceMappingURL=engine.js.map
github mattgrayisok / wulfram-2d / _assets / js / server / ServerWorld.js View on Github external
ServerWorld.prototype.physicsTick = function(){
	this.physicsTickCounter++;
	var self = this;

	_.forEach(this.worldState._state.players, function(player){
		player.server_applyStateForPhysicsTick(self.physicsTickCounter);
	});

	this.worldState.recordPlayerStatesForThisTick(self.physicsTickCounter);

	Matter.Engine.update(this.physicsEngine, global.config.physicsClock_ms);

}
github lepunk / react-native-videos / FlappyBird / Physics.js View on Github external
world.gravity.y = 1.2;

                addPipesAtLocation((Constants.MAX_WIDTH * 2) - (Constants.PIPE_WIDTH / 2), world, entities);
                addPipesAtLocation((Constants.MAX_WIDTH * 3) - (Constants.PIPE_WIDTH / 2), world, entities);
            }

            hadTouches = true;
            Matter.Body.setVelocity( bird, {
                x: bird.velocity.x,
                y: -10
            });
        }

    });

    Matter.Engine.update(engine, time.delta);

    Object.keys(entities).forEach(key => {
        if (key.indexOf("pipe") === 0 && entities.hasOwnProperty(key)){
            Matter.Body.translate(entities[key].body, {x: -2, y: 0});

            if (key.indexOf("Top") !== -1 && parseInt(key.replace("pipe", "")) % 2 === 0){
                if (entities[key].body.position.x <= bird.position.x && !entities[key].scored){
                    entities[key].scored = true;
                    dispatch({ type: "score" });
                }

                if (entities[key].body.position.x <= -1 * (Constants.PIPE_WIDTH / 2)){
                    let pipeIndex = parseInt(key.replace("pipe", ""));
                    delete(entities["pipe" + (pipeIndex - 1) + "Top"]);
                    delete(entities["pipe" + (pipeIndex - 1)]);
                    delete(entities["pipe" + pipeIndex + "Top"]);