Skip to content

Commit 9f9a49e

Browse files
committed
GO update.
1 parent bd367f6 commit 9f9a49e

1 file changed

Lines changed: 21 additions & 264 deletions

File tree

v3/src/gameobjects/GameObject.js

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

7-
// var CONST = require('../const');
87
var MATH_CONST = require('../math/const');
8+
var BlendModes = require('../renderer/BlendModes');
99
var ScaleModes = require('../renderer/ScaleModes');
10-
var Component = require('../components');
1110
var WrapAngle = require('../math/angle/Wrap');
1211

1312
/**
1413
* This is the base Game Object class that you can use when creating your own extended Game Objects.
15-
* It hides away the 'private' stuff and exposes only the useful getters, setters and properties.
1614
*
1715
* @class
1816
*/
1917

20-
// Phaser.Texture and Phaser.Frame objects passed in here, instead of looked-up.
21-
// Allows override from non-standard GO types
18+
// Texture is globally shared between GameObjects, not specific to this one
19+
// Frame is globally shared between GameObjects, not specific to this one
2220

23-
var GameObject = function (state, x, y, texture, frame, parent)
21+
var GameObject = function (state, x, y, texture, frame)
2422
{
2523
this.state = state;
2624

2725
this.game = state.sys.game;
2826

2927
this.name = '';
3028

31-
this.type = 0;
32-
33-
this.parent = parent;
34-
35-
// Texture is globally shared between GameObjects, not specific to this one
3629
this.texture = texture;
3730

38-
// Frame is globally shared between GameObjects, not specific to this one
3931
this.frame = frame;
4032

41-
// All GameObjects have the following components, always:
42-
this.transform = new Component.Transform2D(x, y);
43-
44-
this.anchor = new Component.Anchor();
45-
46-
// Optional? Maybe set on a per GO basis?
47-
this.data = new Component.Data(this);
48-
49-
this.color = new Component.Color(this);
50-
51-
// ----------------------------------------------------------------
52-
// ----------------------------------------------------------------
53-
// The following properties are debatable to have in this class
54-
// ----------------------------------------------------------------
55-
// ----------------------------------------------------------------
56-
33+
this.x = x;
34+
this.y = y;
35+
this.z = 0;
36+
this.scaleX = 1;
37+
this.scaleY = 1;
38+
this.rotation = 0;
39+
this.anchorX = 0;
40+
this.anchorY = 0;
41+
42+
this.alpha = 1;
43+
this.blendMode = BlendModes.NORMAL;
5744
this.scaleMode = ScaleModes.DEFAULT;
5845

59-
// Allows you to turn off a GameObject from rendering, but still render its children (if it has any)
60-
// Maybe this should move?
61-
// this.skipRender = (key === undefined);
62-
this.skipRender = false;
63-
6446
this.visible = true;
65-
66-
// Either null, or the Children component
67-
this.children = null;
68-
69-
this.exists = true;
7047
};
7148

7249
GameObject.prototype.constructor = GameObject;
7350

7451
GameObject.prototype = {
7552

76-
preUpdate: function ()
77-
{
78-
// NOOP
79-
},
80-
81-
update: function ()
82-
{
83-
// NOOP
84-
},
85-
86-
postUpdate: function ()
87-
{
88-
// NOOP
89-
},
90-
91-
render: function ()
92-
{
93-
// NOOP
94-
},
95-
9653
destroy: function ()
9754
{
98-
// NOOP
55+
this.state = undefined;
56+
this.game = undefined;
57+
this.texture = undefined;
58+
this.frame = undefined;
9959
}
10060

10161
};
10262

10363
Object.defineProperties(GameObject.prototype, {
10464

105-
// Transform getters / setters
106-
107-
x: {
108-
109-
enumerable: true,
110-
111-
get: function ()
112-
{
113-
return this.transform.x;
114-
},
115-
116-
set: function (value)
117-
{
118-
this.transform.x = value;
119-
}
120-
121-
},
122-
123-
y: {
124-
125-
enumerable: true,
126-
127-
get: function ()
128-
{
129-
return this.transform.y;
130-
},
131-
132-
set: function (value)
133-
{
134-
this.transform.y = value;
135-
}
136-
137-
},
138-
139-
scale: {
140-
141-
enumerable: true,
142-
143-
get: function ()
144-
{
145-
return this.transform.scaleX;
146-
},
147-
148-
set: function (value)
149-
{
150-
this.transform.scaleX = value;
151-
this.transform.scaleY = value;
152-
}
153-
154-
},
155-
156-
scaleX: {
157-
158-
enumerable: true,
159-
160-
get: function ()
161-
{
162-
return this.transform.scaleX;
163-
},
164-
165-
set: function (value)
166-
{
167-
this.transform.scaleX = value;
168-
}
169-
170-
},
171-
172-
scaleY: {
173-
174-
enumerable: true,
175-
176-
get: function ()
177-
{
178-
return this.transform.scaleY;
179-
},
180-
181-
set: function (value)
182-
{
183-
this.transform.scaleY = value;
184-
}
185-
186-
},
187-
188-
rotation: {
189-
190-
enumerable: true,
191-
192-
get: function ()
193-
{
194-
return this.transform.angle;
195-
},
196-
197-
set: function (value)
198-
{
199-
this.transform.angle = value;
200-
}
201-
202-
},
203-
20465
angle: {
20566

20667
enumerable: true,
20768

20869
get: function ()
20970
{
210-
return WrapAngle(this.transform.angle * MATH_CONST.RAD_TO_DEG);
71+
return WrapAngle(this.rotation * MATH_CONST.RAD_TO_DEG);
21172
},
21273

21374
set: function (value)
21475
{
21576
// value is in degrees
216-
this.transform.angle = WrapAngle(value * MATH_CONST.DEG_TO_RAD);
217-
}
218-
219-
},
220-
221-
anchorX: {
222-
223-
enumerable: true,
224-
225-
get: function ()
226-
{
227-
return this.anchor.getX();
228-
},
229-
230-
set: function (value)
231-
{
232-
this.anchor.setX(value);
233-
}
234-
235-
},
236-
237-
anchorY: {
238-
239-
enumerable: true,
240-
241-
get: function ()
242-
{
243-
return this.anchor.getY();
244-
},
245-
246-
set: function (value)
247-
{
248-
this.anchor.setY(value);
249-
}
250-
251-
},
252-
253-
/*
254-
pivotX: {
255-
256-
enumerable: true,
257-
258-
get: function ()
259-
{
260-
return this.transform._pivotX;
261-
},
262-
263-
set: function (value)
264-
{
265-
this.transform._pivotX = value;
266-
this.transform.dirty = true;
267-
this.transform.updateCache();
268-
}
269-
270-
},
271-
272-
pivotY: {
273-
274-
enumerable: true,
275-
276-
get: function ()
277-
{
278-
return this.transform._pivotY;
279-
},
280-
281-
set: function (value)
282-
{
283-
this.transform._pivotY = value;
284-
this.transform.dirty = true;
285-
this.transform.updateCache();
286-
}
287-
288-
},
289-
*/
290-
291-
// Color getters / setters
292-
293-
alpha: {
294-
295-
enumerable: true,
296-
297-
get: function ()
298-
{
299-
return this.color._alpha;
300-
},
301-
302-
set: function (value)
303-
{
304-
this.color.alpha = value;
305-
}
306-
307-
},
308-
309-
blendMode: {
310-
311-
enumerable: true,
312-
313-
get: function ()
314-
{
315-
return this.color._blendMode;
316-
},
317-
318-
set: function (value)
319-
{
320-
this.color.blendMode = value;
77+
this.rotation = WrapAngle(value * MATH_CONST.DEG_TO_RAD);
32178
}
32279

32380
}

0 commit comments

Comments
 (0)