forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectFactory.js
More file actions
290 lines (232 loc) · 7.85 KB
/
Copy pathGameObjectFactory.js
File metadata and controls
290 lines (232 loc) · 7.85 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.GameObjectFactory
*/
/**
* Description.
*
* @class Phaser.GameObjectFactory
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
Phaser.GameObjectFactory = function (game) {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = this.game.world;
};
Phaser.GameObjectFactory.prototype = {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
* @default
*/
game: null,
/**
* @property {Phaser.World} world - A reference to the game world.
* @default
*/
world: null,
/**
* Description.
* @method existing.
* @param {object} - Description.
* @return {boolean} Description.
*/
existing: function (object) {
return this.world.add(object);
},
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @method sprite
* @param {number} x - X position of the new sprite.
* @param {number} y - Y position of the new sprite.
* @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture.
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Description} Description.
*/
sprite: function (x, y, key, frame) {
return this.world.create(x, y, key, frame);
},
/**
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
*
* @method child
* @param {Phaser.Group} group - The Group to add this child to.
* @param {number} x - X position of the new sprite.
* @param {number} y - Y position of the new sprite.
* @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture.
* @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
* @returns {Description} Description.
*/
child: function (group, x, y, key, frame) {
return group.create(x, y, key, frame);
},
/**
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
*
* @method tween
* @param {object} obj - Object the tween will be run on.
* @return {Description} Description.
*/
tween: function (obj) {
return this.game.tweens.create(obj);
},
/**
* Description.
*
* @method group
* @param {Description} parent - Description.
* @param {Description} name - Description.
* @return {Description} Description.
*/
group: function (parent, name) {
return new Phaser.Group(this.game, parent, name);
},
/**
* Description.
*
* @method audio
* @param {Description} key - Description.
* @param {Description} volume - Description.
* @param {Description} loop - Description.
* @return {Description} Description.
*/
audio: function (key, volume, loop) {
return this.game.sound.add(key, volume, loop);
},
/**
* Description.
*
* @method tileSprite
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} width - Description.
* @param {Description} height - Description.
* @param {Description} key - Description.
* @param {Description} frame - Description.
* @return {Description} Description.
*/
tileSprite: function (x, y, width, height, key, frame) {
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
},
/**
* Description.
*
* @method text
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} text - Description.
* @param {Description} style - Description.
*/
text: function (x, y, text, style) {
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
},
/**
* Description.
*
* @method button
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} callback - Description.
* @param {Description} callbackContext - Description.
* @param {Description} overFrame - Description.
* @param {Description} outFrame - Description.
* @param {Description} downFrame - Description.
* @return {Description} Description.
*/
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
},
/**
* Description.
*
* @method graphics
* @param {Description} x - Description.
* @param {Description} y - Description.
* @return {Description} Description.
*/
graphics: function (x, y) {
return this.world.add(new Phaser.Graphics(this.game, x, y));
},
/**
* Description.
*
* @method emitter
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} maxParticles - Description.
* @return {Description} Description.
*/
emitter: function (x, y, maxParticles) {
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
},
/**
* Description.
*
* @method bitmapText
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} text - Description.
* @param {Description} style - Description.
* @return {Description} Description.
*/
bitmapText: function (x, y, text, style) {
return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
},
/**
* Description.
*
* @method tilemap
* @param {Description} key - Description.
* @return {Description} Description.
*/
tilemap: function (key) {
return new Phaser.Tilemap(this.game, key);
},
/**
* Description.
*
* @method tilemap
* @param {Description} key - Description.
* @return {Description} Description.
*/
tileset: function (key) {
return this.game.cache.getTileset(key);
},
/**
* Description.
*
* @method tileSprite
* @param {Description} x - Description.
* @param {Description} y - Description.
* @param {Description} width - Description.
* @param {Description} height - Description.
* @param {Description} key - Description.
* @param {Description} frame - Description.
* @return {Description} Description.
*/
tilemapLayer: function (x, y, width, height, tileset, tilemap, layer) {
return this.world.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer));
},
/**
* Description.
*
* @method renderTexture
* @param {Description} key - Description.
* @param {Description} width - Description.
* @param {Description} height - Description.
* @return {Description} Description.
*/
renderTexture: function (key, width, height) {
var texture = new Phaser.RenderTexture(this.game, key, width, height);
this.game.cache.addRenderTexture(key, texture);
return texture;
},
};