Skip to content

Commit d42aa4c

Browse files
committed
Updated Container class and factory
1 parent b279308 commit d42aa4c

2 files changed

Lines changed: 137 additions & 17 deletions

File tree

v3/src/gameobjects/container/Container.js

Lines changed: 131 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,49 @@
11
var Class = require('../../utils/Class');
2+
var Components = require('../components');
23
var DataProxy = require('../components/DataProxy');
3-
var List = require('../../structs/List');
4+
var DisplayList = require('../../scene/plugins/DisplayList');
5+
var TransformMatrix = require('../components/TransformMatrix');
46

57
var Container = new Class({
68

7-
Extends: List,
9+
// Extends: DisplayList,
10+
11+
// Mixins: [
12+
// Components.Visible,
13+
// SpriteRender
14+
// ],
815

916
initialize:
1017

1118
function Container (scene, x, y)
1219
{
13-
List.call(this, this);
20+
// this.list = children
21+
// DisplayList.call(this, scene);
1422

1523
this.scene = scene;
1624

1725
this.type = 'Container';
1826

1927
this.name = '';
2028

29+
// Likely swap for a ProcessQueue to make it iteration safe
30+
this.list = [];
31+
2132
this.active = true;
2233

2334
this.data = new DataProxy(scene, this);
2435

36+
this._depth = 0;
37+
38+
this._transform = new TransformMatrix();
39+
2540
this._x = x;
2641
this._y = y;
27-
this._z = 0;
28-
this._w = 0;
29-
3042
this._scaleX = 1;
3143
this._scaleY = 1;
3244
this._rotation = 0;
33-
this._depth = 0;
45+
46+
this._visible = true;
3447
},
3548

3649
x: {
@@ -42,14 +55,11 @@ var Container = new Class({
4255

4356
set: function (value)
4457
{
45-
var diff = this._x - value;
46-
4758
this._x = value;
4859

49-
// Update all children
5060
for (var i = 0; i < this.list.length; i++)
5161
{
52-
this.list[i].x += diff;
62+
// this.list[i].depth = value;
5363
}
5464
}
5565

@@ -64,19 +74,125 @@ var Container = new Class({
6474

6575
set: function (value)
6676
{
67-
var diff = this._y - value;
68-
6977
this._y = value;
7078

71-
// Update all children
7279
for (var i = 0; i < this.list.length; i++)
7380
{
74-
this.list[i].y += diff;
81+
// this.list[i].depth = value;
7582
}
7683
}
7784

7885
},
7986

87+
depth: {
88+
89+
get: function ()
90+
{
91+
return this._depth;
92+
},
93+
94+
set: function (value)
95+
{
96+
this._depth = value;
97+
98+
for (var i = 0; i < this.list.length; i++)
99+
{
100+
this.list[i].depth = value;
101+
}
102+
}
103+
104+
},
105+
106+
setDepth: function (value)
107+
{
108+
if (value === undefined) { value = 0; }
109+
110+
this.depth = value;
111+
112+
return this;
113+
},
114+
115+
visible: {
116+
117+
get: function ()
118+
{
119+
return this._visible;
120+
},
121+
122+
set: function (value)
123+
{
124+
if (value)
125+
{
126+
this._visible = true;
127+
}
128+
else
129+
{
130+
this._visible = false;
131+
}
132+
133+
for (var i = 0; i < this.list.length; i++)
134+
{
135+
this.list[i].visible = value;
136+
}
137+
}
138+
139+
},
140+
141+
setVisible: function (value)
142+
{
143+
this.visible = value;
144+
145+
return this;
146+
},
147+
148+
add: function (child)
149+
{
150+
// Don't allow containers to be added
151+
152+
// Is child already in this container?
153+
154+
if (this.getIndex(child) === -1 && child.parent !== this)
155+
{
156+
// No, good ...
157+
this.scene.sys.updateList.remove(child);
158+
159+
if (child.parent)
160+
{
161+
child.parent.remove(child);
162+
}
163+
164+
child.parent = this;
165+
166+
this.list.push(child);
167+
168+
// this.scene.sys.sortChildrenFlag = true;
169+
}
170+
171+
return child;
172+
},
173+
174+
remove: function (child)
175+
{
176+
var index = this.list.indexOf(child);
177+
178+
if (index !== -1)
179+
{
180+
// Not iteration safe - use ProcessQueue instead?
181+
this.list.splice(index, 1);
182+
183+
child.parent = null;
184+
185+
// this.scene.sys.sortChildrenFlag = true;
186+
}
187+
188+
return child;
189+
},
190+
191+
preUpdate: function (time, delta)
192+
{
193+
// iterate children and call preUpdate on them, as they won't be part of the Scenes updateList
194+
},
195+
80196
setActive: function (value)
81197
{
82198
this.active = value;
@@ -105,7 +221,6 @@ var Container = new Class({
105221

106222
destroy: function ()
107223
{
108-
109224
}
110225

111226
});

v3/src/gameobjects/container/ContainerFactory.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@ var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
1111

1212
GameObjectFactory.register('container', function (x, y)
1313
{
14-
return new Container(this.scene, x, y);
14+
var container = new Container(this.scene, x, y);
15+
16+
// this.displayList.add(container);
17+
this.updateList.add(container);
18+
19+
return container;
1520
});

0 commit comments

Comments
 (0)