mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
refactored Mater.Gui
This commit is contained in:
parent
eee9a7b21b
commit
d154fc7ac7
1 changed files with 28 additions and 25 deletions
|
@ -162,31 +162,7 @@ var Gui = {};
|
|||
var render = datGui.addFolder('Render');
|
||||
|
||||
render.add(gui, 'renderer', ['canvas', 'webgl'])
|
||||
.onFinishChange(function(value) {
|
||||
var controller;
|
||||
|
||||
if (value === 'canvas')
|
||||
controller = Render;
|
||||
|
||||
if (value === 'webgl')
|
||||
controller = RenderPixi;
|
||||
|
||||
// remove old canvas
|
||||
engine.render.element.removeChild(engine.render.canvas);
|
||||
|
||||
// create new renderer using the same options object
|
||||
var options = engine.render.options;
|
||||
|
||||
engine.render = controller.create({
|
||||
element: engine.render.element,
|
||||
options: options
|
||||
});
|
||||
|
||||
engine.render.options = options;
|
||||
|
||||
// bind the mouse to the new canvas
|
||||
Mouse.setElement(engine.input.mouse, engine.render.canvas);
|
||||
});
|
||||
.onFinishChange(function(value) { _setRenderer(gui, value); });
|
||||
|
||||
render.add(engine.render.options, 'wireframes');
|
||||
render.add(engine.render.options, 'showDebug');
|
||||
|
@ -204,6 +180,33 @@ var Gui = {};
|
|||
render.open();
|
||||
};
|
||||
|
||||
var _setRenderer = function(gui, rendererName) {
|
||||
var engine = gui.engine,
|
||||
controller;
|
||||
|
||||
if (rendererName === 'canvas')
|
||||
controller = Render;
|
||||
|
||||
if (rendererName === 'webgl')
|
||||
controller = RenderPixi;
|
||||
|
||||
// remove old canvas
|
||||
engine.render.element.removeChild(engine.render.canvas);
|
||||
|
||||
// create new renderer using the same options object
|
||||
var options = engine.render.options;
|
||||
|
||||
engine.render = controller.create({
|
||||
element: engine.render.element,
|
||||
options: options
|
||||
});
|
||||
|
||||
engine.render.options = options;
|
||||
|
||||
// bind the mouse to the new canvas
|
||||
Mouse.setElement(engine.input.mouse, engine.render.canvas);
|
||||
};
|
||||
|
||||
var _addBody = function(gui) {
|
||||
var engine = gui.engine;
|
||||
|
||||
|
|
Loading…
Reference in a new issue