From 01bc8132f1da5058df4fcebb12f0d354bd011336 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 17 Jan 2015 14:22:30 +0000 Subject: [PATCH] removed Render.setBackground (now use render.options) --- src/render/Render.js | 48 ++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/render/Render.js b/src/render/Render.js index e90301b..cdf7e41 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -67,8 +67,6 @@ var Render = {}; } }; - Render.setBackground(render, render.options.background); - if (render.options.pixelRatio !== 1) { Render.setPixelRatio(render, render.options.pixelRatio); } @@ -116,25 +114,6 @@ var Render = {}; render.context.scale(pixelRatio, pixelRatio); }; - /** - * Sets the background CSS property of the canvas - * @method setBackground - * @param {render} render - * @param {string} background - */ - Render.setBackground = function(render, background) { - if (render.currentBackground !== background) { - var cssBackground = background; - - if (/(jpg|gif|png)$/.test(background)) - cssBackground = 'url(' + background + ')'; - - render.canvas.style.background = cssBackground; - render.canvas.style.backgroundSize = "contain"; - render.currentBackground = background; - } - }; - /** * Renders the given `engine`'s `Matter.World` object. * This is the entry point for all rendering and should be called every time the scene changes. @@ -149,15 +128,14 @@ var Render = {}; options = render.options, allBodies = Composite.allBodies(world), allConstraints = Composite.allConstraints(world), + background = options.wireframes ? options.wireframeBackground : options.background, bodies = [], constraints = [], i; - if (options.wireframes) { - Render.setBackground(render, options.wireframeBackground); - } else { - Render.setBackground(render, options.background); - } + // apply background if it has changed + if (render.currentBackground !== background) + _applyBackground(render, background); // clear the canvas with a transparent fill, to allow the canvas background to show context.globalCompositeOperation = 'source-in'; @@ -926,6 +904,24 @@ var Render = {}; return image; }; + /** + * Applies the background to the canvas using CSS. + * @method applyBackground + * @private + * @param {render} render + * @param {string} background + */ + var _applyBackground = function(render, background) { + var cssBackground = background; + + if (/(jpg|gif|png)$/.test(background)) + cssBackground = 'url(' + background + ')'; + + render.canvas.style.background = cssBackground; + render.canvas.style.backgroundSize = "contain"; + render.currentBackground = background; + }; + /* * * Properties Documentation