Skip to content

Commit fb3bb4b

Browse files
committed
Refactored into new Base Game Object class, that Image and Sprite (and everything else) will now extend. Much more versatile, and a lot less code duplication.
1 parent b49edb7 commit fb3bb4b

10 files changed

Lines changed: 822 additions & 112 deletions

File tree

build/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
<script src="$path/src/components/Transform.js"></script>
179179
<script src="$path/src/components/UpdateManager.js"></script>
180180
181+
<script src="$path/src/gameobjects/GameObject.js"></script>
181182
<script src="$path/src/gameobjects/Factory.js"></script>
182183
<script src="$path/src/gameobjects/GameObjectCreator.js"></script>
183184

src/components/Color.js

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Phaser.Component.Color.prototype = {
6464
this._a = (alpha) ? alpha : 1;
6565
}
6666

67-
this.setDirty();
67+
this.dirty = true;
6868
},
6969

7070
clearTint: function ()
@@ -90,21 +90,7 @@ Phaser.Component.Color.prototype = {
9090

9191
this._hasTint = true;
9292

93-
this.setDirty();
94-
},
95-
96-
getBlendMode: function ()
97-
{
98-
return this._blendMode;
99-
},
100-
101-
setBlendMode: function (blendMode)
102-
{
103-
if (blendMode >= 0 && blendMode <= 16)
104-
{
105-
this._blendMode = blendMode;
106-
this.setDirty();
107-
}
93+
this.dirty = true;
10894
},
10995

11096
// Called by the Dirty Manager
@@ -122,16 +108,6 @@ Phaser.Component.Color.prototype = {
122108

123109
},
124110

125-
setDirty: function ()
126-
{
127-
if (!this._dirty)
128-
{
129-
this.game.updates.add(this);
130-
}
131-
132-
this._dirty = true;
133-
},
134-
135111
getColor: function (value)
136112
{
137113
return (value >> 16) + (value & 0xff00) + ((value & 0xff) << 16);
@@ -155,6 +131,34 @@ Phaser.Component.Color.prototype = {
155131

156132
Object.defineProperties(Phaser.Component.Color.prototype, {
157133

134+
dirty: {
135+
136+
enumerable: true,
137+
138+
get: function ()
139+
{
140+
return this._dirty;
141+
},
142+
143+
set: function (value)
144+
{
145+
if (value)
146+
{
147+
if (!this._dirty)
148+
{
149+
this.game.updates.add(this);
150+
}
151+
152+
this._dirty = true;
153+
}
154+
else
155+
{
156+
this._dirty = false;
157+
}
158+
}
159+
160+
},
161+
158162
tintTopLeft: {
159163

160164
enumerable: true,
@@ -168,7 +172,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
168172
{
169173
this._tint.topLeft = value;
170174
this._glTint.topLeft = this.getColor(value);
171-
this.setDirty();
175+
this.dirty = true;
172176
}
173177

174178
},
@@ -186,7 +190,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
186190
{
187191
this._tint.topRight = value;
188192
this._glTint.topRight = this.getColor(value);
189-
this.setDirty();
193+
this.dirty = true;
190194
}
191195

192196
},
@@ -204,7 +208,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
204208
{
205209
this._tint.bottomLeft = value;
206210
this._glTint.bottomLeft = this.getColor(value);
207-
this.setDirty();
211+
this.dirty = true;
208212
}
209213

210214
},
@@ -222,7 +226,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
222226
{
223227
this._tint.bottomRight = value;
224228
this._glTint.bottomRight = this.getColor(value);
225-
this.setDirty();
229+
this.dirty = true;
226230
}
227231

228232
},
@@ -257,7 +261,27 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
257261
if (value !== this._alpha)
258262
{
259263
this._alpha = value;
260-
this.setDirty();
264+
this.dirty = true;
265+
}
266+
}
267+
268+
},
269+
270+
blendMode: {
271+
272+
enumerable: true,
273+
274+
get: function ()
275+
{
276+
return this._blendMode;
277+
},
278+
279+
set: function (value)
280+
{
281+
if (value !== this._blendMode && value >= 0 && value <= 16)
282+
{
283+
this._blendMode = value;
284+
this.dirty = true;
261285
}
262286
}
263287

@@ -294,7 +318,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
294318
{
295319
this._a = value;
296320
this._hasBackground = true;
297-
this.setDirty();
321+
this.dirty = true;
298322
}
299323
}
300324

@@ -315,7 +339,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
315339
{
316340
this._r = value | 0;
317341
this._hasBackground = true;
318-
this.setDirty();
342+
this.dirty = true;
319343
}
320344
}
321345

@@ -336,7 +360,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
336360
{
337361
this._g = value | 0;
338362
this._hasBackground = true;
339-
this.setDirty();
363+
this.dirty = true;
340364
}
341365
}
342366

@@ -357,7 +381,7 @@ Object.defineProperties(Phaser.Component.Color.prototype, {
357381
{
358382
this._b = value | 0;
359383
this._hasBackground = true;
360-
this.setDirty();
384+
this.dirty = true;
361385
}
362386
}
363387

src/components/Transform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ Phaser.Component.Transform = function (gameObject, x, y, scaleX, scaleY)
5151
this._worldScaleX = scaleX;
5252
this._worldScaleY = scaleY;
5353

54+
// this._glVertexDataX1 =
55+
5456
this._dirty = true;
55-
57+
5658
this.game.updates.add(this);
5759

5860
// The parent Transform (NOT the parent GameObject, although very often they are related)

0 commit comments

Comments
 (0)