mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
removed Render.setBackground (now use render.options)
This commit is contained in:
parent
bf3f986ca1
commit
01bc8132f1
1 changed files with 22 additions and 26 deletions
|
@ -67,8 +67,6 @@ var Render = {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Render.setBackground(render, render.options.background);
|
|
||||||
|
|
||||||
if (render.options.pixelRatio !== 1) {
|
if (render.options.pixelRatio !== 1) {
|
||||||
Render.setPixelRatio(render, render.options.pixelRatio);
|
Render.setPixelRatio(render, render.options.pixelRatio);
|
||||||
}
|
}
|
||||||
|
@ -116,25 +114,6 @@ var Render = {};
|
||||||
render.context.scale(pixelRatio, pixelRatio);
|
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.
|
* 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.
|
* 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,
|
options = render.options,
|
||||||
allBodies = Composite.allBodies(world),
|
allBodies = Composite.allBodies(world),
|
||||||
allConstraints = Composite.allConstraints(world),
|
allConstraints = Composite.allConstraints(world),
|
||||||
|
background = options.wireframes ? options.wireframeBackground : options.background,
|
||||||
bodies = [],
|
bodies = [],
|
||||||
constraints = [],
|
constraints = [],
|
||||||
i;
|
i;
|
||||||
|
|
||||||
if (options.wireframes) {
|
// apply background if it has changed
|
||||||
Render.setBackground(render, options.wireframeBackground);
|
if (render.currentBackground !== background)
|
||||||
} else {
|
_applyBackground(render, background);
|
||||||
Render.setBackground(render, options.background);
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear the canvas with a transparent fill, to allow the canvas background to show
|
// clear the canvas with a transparent fill, to allow the canvas background to show
|
||||||
context.globalCompositeOperation = 'source-in';
|
context.globalCompositeOperation = 'source-in';
|
||||||
|
@ -926,6 +904,24 @@ var Render = {};
|
||||||
return image;
|
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
|
* Properties Documentation
|
||||||
|
|
Loading…
Reference in a new issue