Skip to content

Commit 346fbc2

Browse files
committed
Blitter + Bob now rendering and updating fully.
1 parent 6866e83 commit 346fbc2

5 files changed

Lines changed: 335 additions & 44 deletions

File tree

build/phaser3-config.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@
168168
<script src="$path/src/gameobjects/image/ImageCanvasRenderer.js"></script>
169169
<script src="$path/src/gameobjects/image/ImageWebGLRenderer.js"></script>
170170
171+
<script src="$path/src/gameobjects/blitter/Blitter.js"></script>
172+
<script src="$path/src/gameobjects/blitter/BlitterFactory.js"></script>
173+
<script src="$path/src/gameobjects/blitter/BlitterWebGLRenderer.js"></script>
174+
<script src="$path/src/gameobjects/blitter/Bob.js"></script>
175+
171176
<script src="$path/src/gameobjects/button/Button.js"></script>
172177
<script src="$path/src/gameobjects/button/ButtonFactory.js"></script>
173178

src/gameobjects/blitter/Blitter.js

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
/**
8+
* A Blitter Game Object.
9+
*
10+
* The Blitter Game Object is a special type of Container, that contains Blitter.Bob objects.
11+
* These objects can be thought of as just texture frames with a transform, and nothing more.
12+
* Bobs don't have any update methods, or the ability to have children, or any kind of special effects.
13+
* They are essentially just texture renderers, and the Blitter object creates and manages them.
14+
*
15+
* @class
16+
*/
717
Phaser.GameObject.Blitter = function (state, parent)
818
{
919
Phaser.GameObject.call(this, state, 0, 0, null, null, parent);
@@ -24,38 +34,60 @@ Phaser.GameObject.Blitter.prototype.preUpdate = function ()
2434
}
2535
};
2636

27-
Phaser.GameObject.Blitter.prototype.create = function (frame, x, y, visible, index)
37+
Phaser.GameObject.Blitter.prototype.create = function (x, y, key, frame, visible, index)
2838
{
29-
if (x === undefined) { x = 0; }
30-
if (y === undefined) { y = 0; }
3139
if (visible === undefined) { visible = true; }
3240
if (index === undefined) { index = 0; }
3341

34-
var bob = new Phaser.GameObject.Blitter.Bob(this, frame, x, y, visible);
42+
var bob = new Phaser.GameObject.Blitter.Bob(this, x, y, key, frame, visible);
3543

36-
this.children.addAt(bob, index, true);
44+
this.children.addAt(bob, index, false);
3745

3846
return bob;
3947
};
4048

41-
Phaser.GameObject.Blitter.prototype.createMultiple = function (quantity, frame, visible)
49+
Phaser.GameObject.Blitter.prototype.createFromCallback = function (callback, quantity, key, frame, visible)
4250
{
51+
var bobs = this.createMultiple(quantity, key, frame, visible);
52+
53+
for (var i = 0; i < bobs.length; i++)
54+
{
55+
var bob = bobs[i];
56+
57+
callback.call(this, bob);
58+
}
59+
60+
return bobs;
61+
};
62+
63+
Phaser.GameObject.Blitter.prototype.createMultiple = function (quantity, key, frame, visible)
64+
{
65+
if (frame === undefined) { frame = 0; }
4366
if (visible === undefined) { visible = true; }
4467

68+
if (!Array.isArray(key))
69+
{
70+
key = [ key ];
71+
}
72+
4573
if (!Array.isArray(frame))
4674
{
4775
frame = [ frame ];
4876
}
4977

5078
var bobs = [];
79+
var _this = this;
5180

52-
for (var f = 0; f < frame.length; f++)
81+
key.forEach(function (singleKey)
5382
{
54-
for (var i = 0; i < quantity; i++)
83+
frame.forEach(function (singleFrame)
5584
{
56-
bobs.push(this.create(frame[f], 0, 0, visible));
57-
}
58-
}
85+
for (var i = 0; i < quantity; i++)
86+
{
87+
bobs.push(_this.create(0, 0, singleKey, singleFrame, visible));
88+
}
89+
});
90+
});
5991

6092
return bobs;
6193
};

src/gameobjects/blitter/BlitterWebGLRenderer.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,38 @@ Phaser.Renderer.WebGL.GameObjects.Blitter = {
44
Phaser.GameObject.Blitter.prototype
55
],
66

7-
render: function (renderer, src)
7+
render: function (renderer, src, interpolationPercentage)
88
{
9-
var alpha = src.color.worldAlpha * 255 << 24;
9+
var blitterAlpha = src.color.worldAlpha * 255 << 24;
1010

1111
// Skip rendering?
12-
// if (src.skipRender || !src.visible || alpha === 0 || src.children.list.length === 0)
13-
if (src.skipRender || !src.visible || alpha === 0)
12+
if (src.skipRender || !src.visible || blitterAlpha === 0 || src.children.list.length === 0)
1413
{
1514
return;
1615
}
16+
17+
var bg = src.color._glBg;
18+
var tint = src.color._glTint;
19+
var worldAlpha = src.color._worldAlpha;
1720

1821
// Render children
19-
// for (var i = 0; i < src.children.list.length; i++)
20-
// {
21-
// var child = src.children.list[i];
22+
for (var i = 0; i < src.children.list.length; i++)
23+
{
24+
var bob = src.children.list[i];
25+
var frame = bob.frame;
26+
var alpha = (worldAlpha * bob.alpha) * 255 << 24;
2227

23-
// child.render(renderer, child);
24-
// }
28+
if (!bob.visible || alpha === 0 || !frame.cutWidth || !frame.cutHeight)
29+
{
30+
continue;
31+
}
2532

33+
var index = frame.source.glTextureIndex;
34+
var verts = bob.transform.getVertexData(interpolationPercentage);
35+
36+
// tint and bg values come from the parent Blitter object, not the Bob
37+
renderer.batch.add(frame.source, src.blendMode, verts, frame.uvs, index, alpha, tint, bg);
38+
}
2639
}
2740

2841
};

0 commit comments

Comments
 (0)