Skip to content

Commit

Permalink
removed Render.setBackground (now use render.options)
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 17, 2015
1 parent bf3f986 commit 01bc813
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ var Render = {};
}
};

Render.setBackground(render, render.options.background);

if (render.options.pixelRatio !== 1) {
Render.setPixelRatio(render, render.options.pixelRatio);
}
Expand Down Expand Up @@ -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.
Expand All @@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01bc813

Please sign in to comment.