Skip to content

Commit ec4799c

Browse files
committed
Blitter Bobs can now have alpha and visible of their own.
Blitter now filters children down to a render list if dirty. CanvasRenderer resets alpha in postRender.
1 parent d480263 commit ec4799c

7 files changed

Lines changed: 105 additions & 22 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '1ab7d5b0-f236-11e6-867a-17ae0be84b32'
2+
build: '08a92a10-f248-11e6-9a33-b97a01ee41c2'
33
};
44
module.exports = CHECKSUM;

v3/src/components/Children.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ Object.defineProperties(Children.prototype, {
693693
},
694694

695695
/**
696-
* Returns the the next item (based on the cursor) and advances the cursor.
696+
* Returns the next item (based on the cursor) and advances the cursor.
697697
*
698698
* @name Phaser.ArraySet#next
699699
* @property {any} next
@@ -719,7 +719,7 @@ Object.defineProperties(Children.prototype, {
719719
},
720720

721721
/**
722-
* Returns the the previous item (based on the cursor) and retreats the cursor.
722+
* Returns the previous item (based on the cursor) and retreats the cursor.
723723
*
724724
* @name Phaser.ArraySet#previous
725725
* @property {any} previous

v3/src/gameobjects/blitter/Blitter.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ var Blitter = function (state, x, y, key, frame)
3636
this.type = CONST.BLITTER;
3737

3838
this.children = new Children(this);
39+
40+
this.renderList = [];
41+
42+
this.dirty = false;
3943
};
4044

4145
Blitter.prototype = Object.create(GameObject.prototype);
@@ -60,6 +64,8 @@ Blitter.prototype.create = function (x, y, frame, visible, index)
6064

6165
this.children.addAt(bob, index, false);
6266

67+
this.dirty = true;
68+
6369
return bob;
6470
};
6571

@@ -103,9 +109,25 @@ Blitter.prototype.createMultiple = function (quantity, frame, visible)
103109
return bobs;
104110
};
105111

112+
Blitter.prototype.childCanRender = function (child)
113+
{
114+
return (child.visible && child.alpha > 0);
115+
};
116+
117+
Blitter.prototype.getRenderList = function ()
118+
{
119+
if (this.dirty)
120+
{
121+
this.renderList = this.children.list.filter(this.childCanRender, this);
122+
}
123+
124+
return this.renderList;
125+
};
126+
106127
Blitter.prototype.clear = function ()
107128
{
108129
this.children.removeAll();
130+
this.dirty = true;
109131
};
110132

111133
module.exports = Blitter;

v3/src/gameobjects/blitter/BlitterCanvasRenderer.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@
22
var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage)
33
{
44
var worldAlpha = src.color.worldAlpha;
5-
var len = src.children.list.length;
5+
var list = src.getRenderList();
66

77
// Skip rendering?
88

9-
if (src.skipRender || !src.visible || worldAlpha === 0 || len === 0)
9+
if (src.skipRender || !src.visible || worldAlpha === 0 || list.length === 0)
1010
{
1111
return;
1212
}
1313

1414
renderer.resetTransform();
1515
renderer.setBlendMode(src.blendMode);
16-
renderer.setAlpha(worldAlpha);
16+
17+
var ca = renderer.currentAlpha;
1718

1819
// Render bobs
19-
for (var i = 0; i < len; i++)
20+
for (var i = 0; i < list.length; i++)
2021
{
21-
var bob = src.children.list[i];
22-
var frame = bob.frame;
22+
var bob = list[i];
2323

24-
// if (!bob.visible)
25-
// {
26-
// continue;
27-
// }
24+
if (ca !== bob.alpha)
25+
{
26+
ca = renderer.setAlpha(bob.alpha);
27+
}
2828

29-
renderer.blitImage(bob.x, bob.y, frame);
29+
renderer.blitImage(bob.x, bob.y, bob.frame);
3030
}
3131
};
3232

v3/src/gameobjects/blitter/BlitterWebGLRenderer.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage)
22
{
33
var worldAlpha = src.color.worldAlpha;
4-
var len = src.children.list.length - 1;
4+
var list = src.getRenderList();
55

66
// Skip rendering?
77

8-
if (src.skipRender || !src.visible || worldAlpha === 0 || len === 0)
8+
if (src.skipRender || !src.visible || worldAlpha === 0 || list.length === 0)
99
{
1010
return;
1111
}
1212

1313
// Render bobs
1414

15-
for (var i = 0; i <= len; ++i)
15+
for (var i = 0; i < list.length; i++)
1616
{
17-
var bob = src.children.list[i];
18-
var frame = bob.frame;
17+
var bob = list[i];
1918

20-
renderer.blitterBatch.add(bob.x, bob.y, frame, worldAlpha);
19+
renderer.blitterBatch.add(bob.x, bob.y, bob.frame, bob.alpha);
2120
}
2221
};
2322

v3/src/gameobjects/blitter/Bob.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,68 @@ var Bob = function (blitter, x, y, frame, visible)
55
this.x = x;
66
this.y = y;
77
this.frame = frame;
8-
this.visible = visible;
98
this.data = {};
9+
10+
this._visible = visible;
11+
this._alpha = 1;
1012
};
1113

14+
Bob.prototype.constructor = Bob;
15+
1216
Bob.prototype = {
17+
1318
reset: function (x, y, frame)
1419
{
1520
this.x = x;
1621
this.y = y;
1722
this.frame = frame;
23+
},
24+
25+
destroy: function ()
26+
{
27+
this.parent = undefined;
28+
this.frame = undefined;
29+
this.data = undefined;
1830
}
31+
1932
};
2033

34+
Object.defineProperties(Bob.prototype, {
35+
36+
visible: {
37+
38+
enumerable: true,
39+
40+
get: function ()
41+
{
42+
return this._visible;
43+
},
44+
45+
set: function (value)
46+
{
47+
this._visible = value;
48+
this.parent.dirty = true;
49+
}
50+
51+
},
52+
53+
alpha: {
54+
55+
enumerable: true,
56+
57+
get: function ()
58+
{
59+
return this._alpha;
60+
},
61+
62+
set: function (value)
63+
{
64+
this._alpha = value;
65+
this.parent.dirty = true;
66+
}
67+
68+
}
69+
70+
});
71+
2172
module.exports = Bob;

v3/src/renderer/canvas/CanvasRenderer.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ CanvasRenderer.prototype = {
9898
this.currentContext.globalCompositeOperation = blendMode;
9999
this.currentBlendMode = blendMode;
100100
}
101+
102+
return this.currentBlendMode;
101103
},
102104

103105
setAlpha: function (alpha)
@@ -107,6 +109,8 @@ CanvasRenderer.prototype = {
107109
this.currentContext.globalAlpha = alpha;
108110
this.currentAlpha = alpha;
109111
}
112+
113+
return this.currentAlpha;
110114
},
111115

112116
// Call at the start of the render loop
@@ -159,7 +163,6 @@ CanvasRenderer.prototype = {
159163

160164
// If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops)
161165

162-
163166
if (this.currentAlpha !== 1)
164167
{
165168
ctx.globalAlpha = 1;
@@ -229,6 +232,14 @@ CanvasRenderer.prototype = {
229232
{
230233
// console.log('%c render end ', 'color: #ffffff; background: #ff0000;');
231234

235+
var ctx = this.gameContext;
236+
237+
ctx.globalAlpha = 1;
238+
ctx.globalCompositeOperation = 'source-over';
239+
240+
this.currentAlpha = 1;
241+
this.currentBlendMode = 0;
242+
232243
// Add Post-render hook
233244
},
234245

0 commit comments

Comments
 (0)