From 3750bfc7192421df9dfa2743e1732c49ce15f6dd Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 30 Apr 2014 22:37:46 +0100 Subject: [PATCH] added offset property to Matter.Gui --- src/tools/Gui.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/tools/Gui.js b/src/tools/Gui.js index 1233fc2..c41e5ea 100644 --- a/src/tools/Gui.js +++ b/src/tools/Gui.js @@ -17,9 +17,18 @@ var Gui = {}; * @return {gui} A container for a configured dat.gui */ Gui.create = function(engine, options) { + var _datGuiSupported = window.dat && window.localStorage; + + if (!_datGuiSupported) { + console.log("Could not create GUI. Check dat.gui library is loaded first."); + return; + } + + var datGui = new dat.GUI(options); + var gui = { engine: engine, - datGui: null, + datGui: datGui, amount: 1, size: 40, sides: 4, @@ -27,23 +36,13 @@ var Gui = {}; restitution: 0, friction: 0.1, frictionAir: 0.01, + offset: { x: 0, y: 0 }, renderer: 'canvas' }; - - var _datGuiSupported = window.dat && window.localStorage; - - if (!_datGuiSupported) { - console.log("Could not create GUI. Check dat.gui library is loaded first."); - return; - } - - var datGui = gui.datGui = new dat.GUI(options); if (Resurrect) { - gui.serializer = new Resurrect({ prefix: '$' }); + gui.serializer = new Resurrect({ prefix: '$', cleanup: true }); gui.serializer.parse = gui.serializer.resurrect; - } else { - gui.serializer = JSON; } _initDatGui(gui); @@ -209,7 +208,7 @@ var Gui = {}; }; for (var i = 0; i < gui.amount; i++) { - World.add(engine.world, Bodies.polygon(120 + i * gui.size + i * 50, 200, gui.sides, gui.size, options)); + World.add(engine.world, Bodies.polygon(gui.offset.x + 120 + i * gui.size + i * 50, gui.offset.y + 200, gui.sides, gui.size, options)); } };