var Class = require('../../utils/Class'); var GetValue = require('../../utils/object/GetValue'); var Merge = require('../../utils/object/Merge'); var NOOP = require('../../utils/NOOP'); var Arcade = require('../../physics/arcade/Arcade'); var Impact = require('../../physics/impact/Impact'); var Matter = require('../../physics/matter-js/Matter'); var PhysicsManager = new Class({ initialize: function PhysicsManager(scene){ this.scene = scene; this.gameConfig = scene.sys.game.config.physics; this.defaultSystem = scene.sys.game.config.defaultPhysicsSystem; this.sceneConfig = scene.sys.settings.physics; this.system; this.world = { update: NOOP, postUpdate: NOOP, shutdown: NOOP, destroy: NOOP} ; this.add; } , boot: function (){ var sceneSystem = GetValue(this.sceneConfig, 'system', false ); if (!this.defaultSystem && !sceneSystem) { return ; } var system = (sceneSystem !== false )? sceneSystem: this.defaultSystem; var config = Merge(this.sceneConfig, GetValue(this.gameConfig, system, { } )); switch (system){ case 'arcade': this.system = new Arcade(this, config); break ; case 'impact': this.system = new Impact(this, config); break ; case 'matter': this.system = new Matter(this, config); break ; } } , remove: function (object){ this.world.remove(object); } , update: function (time, delta){ this.world.update(time, delta); } , postUpdate: function (){ this.world.postUpdate(); } , shutdown: function (){ this.world.shutdown(); } , destroy: function (){ this.world.destroy(); } } ); module.exports = PhysicsManager;