forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlitter.js
More file actions
138 lines (107 loc) · 3.29 KB
/
Copy pathBlitter.js
File metadata and controls
138 lines (107 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var BlitterRender = require('./BlitterRender');
var Bob = require('./Bob');
var Class = require('../../utils/Class');
var Components = require('../components');
var DisplayList = require('../../scene/plugins/DisplayList');
var GameObject = require('../GameObject');
/**
* A Blitter Game Object.
*
* The Blitter Game Object is a special type of Container, that contains Blitter.Bob objects.
* These objects can be thought of as just texture frames with a position and nothing more.
* Bobs don't have any update methods, or the ability to have children, or any kind of special effects.
* They are essentially just super-fast texture frame renderers, and the Blitter object creates and manages them.
*/
var Blitter = new Class({
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.RenderTarget,
Components.ScaleMode,
Components.Size,
Components.Texture,
Components.Transform,
Components.Visible,
Components.ScrollFactor,
BlitterRender
],
initialize:
function Blitter (scene, x, y, texture, frame)
{
GameObject.call(this, scene, 'Blitter');
this.setTexture(texture, frame);
this.setPosition(x, y);
this.children = new DisplayList(this);
this.renderList = [];
this.dirty = false;
},
// frame MUST be part of the Blitter texture
create: function (x, y, frame, visible, index)
{
if (visible === undefined) { visible = true; }
if (index === undefined) { index = this.children.length; }
if (frame === undefined)
{
frame = this.frame;
}
else
{
frame = this.texture.get(frame);
}
var bob = new Bob(this, x, y, frame, visible);
this.children.addAt(bob, index, false);
this.dirty = true;
return bob;
},
// frame MUST be part of the Blitter texture
createFromCallback: function (callback, quantity, frame, visible)
{
var bobs = this.createMultiple(quantity, frame, visible);
for (var i = 0; i < bobs.length; i++)
{
var bob = bobs[i];
callback.call(this, bob, i);
}
return bobs;
},
// frame MUST be part of the Blitter texture
createMultiple: function (quantity, frame, visible)
{
if (frame === undefined) { frame = this.frame; }
if (visible === undefined) { visible = true; }
if (!Array.isArray(frame))
{
frame = [ frame ];
}
var bobs = [];
var _this = this;
frame.forEach(function (singleFrame)
{
for (var i = 0; i < quantity; i++)
{
bobs.push(_this.create(0, 0, singleFrame, visible));
}
});
return bobs;
},
childCanRender: function (child)
{
return (child.visible && child.alpha > 0);
},
getRenderList: function ()
{
if (this.dirty)
{
this.renderList = this.children.list.filter(this.childCanRender, this);
this.dirty = false;
}
return this.renderList;
},
clear: function ()
{
this.children.removeAll();
this.dirty = true;
}
});
module.exports = Blitter;