diff --git a/src/core/Engine.js b/src/core/Engine.js index 41c13e9..f77d7c9 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -29,6 +29,11 @@ var Engine = {}; * @return {engine} engine */ Engine.create = function(element, options) { + + // options may be passed as the first (and only) argument + options = Common.isElement(element) ? options : element; + element = Common.isElement(element) ? element : null; + var defaults = { enabled: true, positionIterations: 6, @@ -52,20 +57,16 @@ var Engine = {}; correction: 1, deltaMin: 1000 / _fps, deltaMax: 1000 / (_fps * 0.5) + }, + render: { + element: element, + controller: Render } }; var engine = Common.extend(defaults, options); - engine = Common.isElement(element) ? (engine || {}) : element; - - // create default renderer only if no custom renderer set - // but still allow engine.render.engine to pass through if set - if (!engine.render || (engine.render && !engine.render.controller)) { - engine.render = Render.create(engine.render); - if (Common.isElement(element)) - element.appendChild(engine.render.canvas); - } + engine.render = engine.render.controller.create(engine.render); engine.world = World.create(engine.world); engine.metrics = engine.metrics || Metrics.create(); engine.input.mouse = engine.input.mouse || Mouse.create(engine.render.canvas); diff --git a/src/render/Render.js b/src/render/Render.js index 8e6522b..0d01fef 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -21,6 +21,8 @@ var Render = {}; Render.create = function(options) { var defaults = { controller: Render, + element: null, + canvas: null, options: { width: 800, height: 600, @@ -49,6 +51,12 @@ var Render = {}; Render.setBackground(render, render.options.background); + if (Common.isElement(render.element)) { + render.element.appendChild(render.canvas); + } else { + Common.log('No "render.element" passed, "render.canvas" was not inserted into document.', 'warn'); + } + return render; };