Skip to content

Commit fdb2e2f

Browse files
committed
Added Camera.setBackgroundColor
1 parent 25356ec commit fdb2e2f

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

v3/src/camera/Camera.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Rectangle = require('../geom/rectangle/Rectangle');
22
var TransformMatrix = require('../components/TransformMatrix');
3+
var ValueToColor = require('../graphics/color/ValueToColor');
34

45
var Camera = function (x, y, width, height)
56
{
@@ -41,12 +42,25 @@ var Camera = function (x, y, width, height)
4142

4243
// origin
4344
this._follow = null;
45+
46+
this.clearBeforeRender = true;
47+
this.backgroundColor = ValueToColor('rgba(0,0,0,0)');
48+
this.transparent = true;
4449
};
4550

4651
Camera.prototype.constructor = Camera;
4752

4853
Camera.prototype = {
4954

55+
setBackgroundColor: function (color)
56+
{
57+
if (color === undefined) { color = 'rgba(0,0,0,0)'; }
58+
59+
this.backgroundColor = ValueToColor(color);
60+
61+
this.transparent = (this.backgroundColor.alpha === 0);
62+
},
63+
5064
removeBounds: function ()
5165
{
5266
this.useBounds = false;

v3/src/renderer/webgl/WebGLRenderer.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ WebGLRenderer.prototype = {
320320
gl.scissor(this.scissor.x, this.scissor.y, this.scissor.width, this.scissor.height);
321321
}
322322

323-
// We could either clear color or render a quad
324-
var color = this.game.config.backgroundColor;
325-
gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL);
326-
gl.clear(gl.COLOR_BUFFER_BIT);
323+
if (camera.backgroundColor.alphaGL > 0)
324+
{
325+
var color = camera.backgroundColor;
326+
327+
gl.clearColor(color.redGL, color.greenGL, color.blueGL, color.alphaGL);
328+
329+
gl.clear(gl.COLOR_BUFFER_BIT);
330+
}
327331

328332
var list = children.list;
329333
var length = list.length;

v3/src/state/systems/CameraManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ CameraManager.prototype = {
9999
render: function (renderer, children, interpolation)
100100
{
101101
var cameras = this.cameras;
102+
102103
for (var i = 0, l = cameras.length; i < l; ++i)
103104
{
104105
var camera = cameras[i];
@@ -107,7 +108,6 @@ CameraManager.prototype = {
107108

108109
renderer.render(this.state, children, interpolation, camera);
109110
}
110-
111111
},
112112

113113
destroy: function ()

0 commit comments

Comments
 (0)