|
4 | 4 | * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
5 | 5 | */ |
6 | 6 |
|
7 | | -// var CONST = require('../const'); |
8 | 7 | var MATH_CONST = require('../math/const'); |
| 8 | +var BlendModes = require('../renderer/BlendModes'); |
9 | 9 | var ScaleModes = require('../renderer/ScaleModes'); |
10 | | -var Component = require('../components'); |
11 | 10 | var WrapAngle = require('../math/angle/Wrap'); |
12 | 11 |
|
13 | 12 | /** |
14 | 13 | * 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. |
16 | 14 | * |
17 | 15 | * @class |
18 | 16 | */ |
19 | 17 |
|
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 |
22 | 20 |
|
23 | | -var GameObject = function (state, x, y, texture, frame, parent) |
| 21 | +var GameObject = function (state, x, y, texture, frame) |
24 | 22 | { |
25 | 23 | this.state = state; |
26 | 24 |
|
27 | 25 | this.game = state.sys.game; |
28 | 26 |
|
29 | 27 | this.name = ''; |
30 | 28 |
|
31 | | - this.type = 0; |
32 | | - |
33 | | - this.parent = parent; |
34 | | - |
35 | | - // Texture is globally shared between GameObjects, not specific to this one |
36 | 29 | this.texture = texture; |
37 | 30 |
|
38 | | - // Frame is globally shared between GameObjects, not specific to this one |
39 | 31 | this.frame = frame; |
40 | 32 |
|
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; |
57 | 44 | this.scaleMode = ScaleModes.DEFAULT; |
58 | 45 |
|
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 | | - |
64 | 46 | this.visible = true; |
65 | | - |
66 | | - // Either null, or the Children component |
67 | | - this.children = null; |
68 | | - |
69 | | - this.exists = true; |
70 | 47 | }; |
71 | 48 |
|
72 | 49 | GameObject.prototype.constructor = GameObject; |
73 | 50 |
|
74 | 51 | GameObject.prototype = { |
75 | 52 |
|
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 | | - |
96 | 53 | destroy: function () |
97 | 54 | { |
98 | | - // NOOP |
| 55 | + this.state = undefined; |
| 56 | + this.game = undefined; |
| 57 | + this.texture = undefined; |
| 58 | + this.frame = undefined; |
99 | 59 | } |
100 | 60 |
|
101 | 61 | }; |
102 | 62 |
|
103 | 63 | Object.defineProperties(GameObject.prototype, { |
104 | 64 |
|
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 | | - |
204 | 65 | angle: { |
205 | 66 |
|
206 | 67 | enumerable: true, |
207 | 68 |
|
208 | 69 | get: function () |
209 | 70 | { |
210 | | - return WrapAngle(this.transform.angle * MATH_CONST.RAD_TO_DEG); |
| 71 | + return WrapAngle(this.rotation * MATH_CONST.RAD_TO_DEG); |
211 | 72 | }, |
212 | 73 |
|
213 | 74 | set: function (value) |
214 | 75 | { |
215 | 76 | // 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); |
321 | 78 | } |
322 | 79 |
|
323 | 80 | } |
|
0 commit comments