Skip to content

Commit 380e717

Browse files
committed
Finished off missing factories. Moved over the docs. Changed rogue @returns to @return everywhere.
1 parent 6d0dc5e commit 380e717

26 files changed

Lines changed: 640 additions & 228 deletions

build/config.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<script src="$path/src/gameobjects/image/ImageWebGLRenderer.js"></script>
192192
193193
<script src="$path/src/gameobjects/button/Button.js"></script>
194+
<script src="$path/src/gameobjects/button/ButtonFactory.js"></script>
194195
195196
<script src="$path/src/gameobjects/spritebatch/SpriteBatch.js"></script>
196197
<script src="$path/src/gameobjects/spritebatch/SpriteBatchFactory.js"></script>
@@ -223,6 +224,7 @@
223224
{
224225
echo <<<EOL
225226
<script src="$path/src/gameobjects/rope/Rope.js"></script>
227+
<script src="$path/src/gameobjects/rope/RopeFactory.js"></script>
226228
227229
228230
EOL;
@@ -308,6 +310,7 @@
308310
{
309311
echo <<<EOL
310312
<script src="$path/src/gameobjects/retrofont/RetroFont.js"></script>
313+
<script src="$path/src/gameobjects/retrofont/RetroFontFactory.js"></script>
311314
312315
313316
EOL;
@@ -317,6 +320,7 @@
317320
{
318321
echo <<<EOL
319322
<script src="$path/src/gameobjects/video/Video.js"></script>
323+
<script src="$path/src/gameobjects/video/VideoFactory.js"></script>
320324
321325
322326
EOL;

src/gameobjects/Factory.js

Lines changed: 137 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Phaser.GameObjects.Factory.prototype = {
5252
/**
5353
* Adds an existing display object to the game world.
5454
*
55-
* @method Phaser.GameObjectFactory#existing
55+
* @method Phaser.GameObjects.Factory#existing
5656
* @param {any} object - An instance of Phaser.Sprite, Phaser.Button or any other display object.
5757
* @return {any} The child that was added to the World.
5858
*/
@@ -67,7 +67,7 @@ Phaser.GameObjects.Factory.prototype = {
6767
*
6868
* The object can be any JavaScript object or Phaser object such as Sprite.
6969
*
70-
* @method Phaser.GameObjectFactory#tween
70+
* @method Phaser.GameObjects.Factory#tween
7171
* @param {object} object - Object the tween will be run on.
7272
* @return {Phaser.Tween} The newly created Phaser.Tween object.
7373
*/
@@ -80,7 +80,7 @@ Phaser.GameObjects.Factory.prototype = {
8080
/**
8181
* A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
8282
*
83-
* @method Phaser.GameObjectFactory#group
83+
* @method Phaser.GameObjects.Factory#group
8484
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
8585
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
8686
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
@@ -100,7 +100,7 @@ Phaser.GameObjects.Factory.prototype = {
100100
* A Physics Group is the same as an ordinary Group except that is has enableBody turned on by default, so any Sprites it creates
101101
* are automatically given a physics body.
102102
*
103-
* @method Phaser.GameObjectFactory#physicsGroup
103+
* @method Phaser.GameObjects.Factory#physicsGroup
104104
* @param {number} [physicsBodyType=Phaser.Physics.ARCADE] - If enableBody is true this is the type of physics body that is created on new Sprites. Phaser.Physics.ARCADE, Phaser.Physics.P2JS, Phaser.Physics.NINJA, etc.
105105
* @param {any} [parent] - The parent Group or DisplayObjectContainer that will hold this group, if any. If set to null the Group won't be added to the display list. If undefined it will be added to World by default.
106106
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
@@ -116,7 +116,7 @@ Phaser.GameObjects.Factory.prototype = {
116116
/**
117117
* Creates a new Sound object.
118118
*
119-
* @method Phaser.GameObjectFactory#audio
119+
* @method Phaser.GameObjects.Factory#audio
120120
* @param {string} key - The Game.cache key of the sound that this object will use.
121121
* @param {number} [volume=1] - The volume at which the sound will be played.
122122
* @param {boolean} [loop=false] - Whether or not the sound will loop.
@@ -132,7 +132,7 @@ Phaser.GameObjects.Factory.prototype = {
132132
/**
133133
* Creates a new Sound object.
134134
*
135-
* @method Phaser.GameObjectFactory#sound
135+
* @method Phaser.GameObjects.Factory#sound
136136
* @param {string} key - The Game.cache key of the sound that this object will use.
137137
* @param {number} [volume=1] - The volume at which the sound will be played.
138138
* @param {boolean} [loop=false] - Whether or not the sound will loop.
@@ -148,7 +148,7 @@ Phaser.GameObjects.Factory.prototype = {
148148
/**
149149
* Creates a new AudioSprite object.
150150
*
151-
* @method Phaser.GameObjectFactory#audioSprite
151+
* @method Phaser.GameObjects.Factory#audioSprite
152152
* @param {string} key - The Game.cache key of the sound that this object will use.
153153
* @return {Phaser.AudioSprite} The newly created AudioSprite object.
154154
*/
@@ -158,5 +158,135 @@ Phaser.GameObjects.Factory.prototype = {
158158

159159
},
160160

161+
/**
162+
* Create a new Emitter.
163+
*
164+
* A particle emitter can be used for one-time explosions or for
165+
* continuous effects like rain and fire. All it really does is launch Particle objects out
166+
* at set intervals, and fixes their positions and velocities accordingly.
167+
*
168+
* @method Phaser.GameObjects.Factory#emitter
169+
* @param {number} [x=0] - The x coordinate within the Emitter that the particles are emitted from.
170+
* @param {number} [y=0] - The y coordinate within the Emitter that the particles are emitted from.
171+
* @param {number} [maxParticles=50] - The total number of particles in this emitter.
172+
* @return {Phaser.Particles.Arcade.Emitter} The newly created emitter object.
173+
*/
174+
emitter: function (x, y, maxParticles) {
175+
176+
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
177+
178+
},
179+
180+
/**
181+
* Creates a new Phaser.Tilemap object.
182+
*
183+
* The map can either be populated with data from a Tiled JSON file or from a CSV file.
184+
* To do this pass the Cache key as the first parameter. When using Tiled data you need only provide the key.
185+
* When using CSV data you must provide the key and the tileWidth and tileHeight parameters.
186+
* If creating a blank tilemap to be populated later, you can either specify no parameters at all and then use `Tilemap.create` or pass the map and tile dimensions here.
187+
* Note that all Tilemaps use a base tile size to calculate dimensions from, but that a TilemapLayer may have its own unique tile size that overrides it.
188+
*
189+
* @method Phaser.GameObjects.Factory#tilemap
190+
* @param {string} [key] - The key of the tilemap data as stored in the Cache. If you're creating a blank map either leave this parameter out or pass `null`.
191+
* @param {number} [tileWidth=32] - The pixel width of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
192+
* @param {number} [tileHeight=32] - The pixel height of a single map tile. If using CSV data you must specify this. Not required if using Tiled map data.
193+
* @param {number} [width=10] - The width of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
194+
* @param {number} [height=10] - The height of the map in tiles. If this map is created from Tiled or CSV data you don't need to specify this.
195+
* @return {Phaser.Tilemap} The newly created tilemap object.
196+
*/
197+
tilemap: function (key, tileWidth, tileHeight, width, height) {
198+
199+
return new Phaser.Tilemap(this.game, key, tileWidth, tileHeight, width, height);
200+
201+
},
202+
/**
203+
* A dynamic initially blank canvas to which images can be drawn.
204+
*
205+
* @method Phaser.GameObjects.Factory#renderTexture
206+
* @param {number} [width=100] - the width of the RenderTexture.
207+
* @param {number} [height=100] - the height of the RenderTexture.
208+
* @param {string} [key=''] - Asset key for the RenderTexture when stored in the Cache (see addToCache parameter).
209+
* @param {boolean} [addToCache=false] - Should this RenderTexture be added to the Game.Cache? If so you can retrieve it with Cache.getTexture(key)
210+
* @return {Phaser.RenderTexture} The newly created RenderTexture object.
211+
*/
212+
renderTexture: function (width, height, key, addToCache) {
213+
214+
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
215+
if (addToCache === undefined) { addToCache = false; }
216+
217+
var texture = new Phaser.RenderTexture(this.game, width, height, key);
218+
219+
if (addToCache)
220+
{
221+
this.game.cache.addRenderTexture(key, texture);
222+
}
223+
224+
return texture;
225+
226+
},
227+
228+
/**
229+
* Create a BitmapData object.
230+
*
231+
* A BitmapData object can be manipulated and drawn to like a traditional Canvas object and used to texture Sprites.
232+
*
233+
* @method Phaser.GameObjects.Factory#bitmapData
234+
* @param {number} [width=256] - The width of the BitmapData in pixels.
235+
* @param {number} [height=256] - The height of the BitmapData in pixels.
236+
* @param {string} [key=''] - Asset key for the BitmapData when stored in the Cache (see addToCache parameter).
237+
* @param {boolean} [addToCache=false] - Should this BitmapData be added to the Game.Cache? If so you can retrieve it with Cache.getBitmapData(key)
238+
* @return {Phaser.BitmapData} The newly created BitmapData object.
239+
*/
240+
bitmapData: function (width, height, key, addToCache) {
241+
242+
if (addToCache === undefined) { addToCache = false; }
243+
if (key === undefined || key === '') { key = this.game.rnd.uuid(); }
244+
245+
var texture = new Phaser.BitmapData(this.game, key, width, height);
246+
247+
if (addToCache)
248+
{
249+
this.game.cache.addBitmapData(key, texture);
250+
}
251+
252+
return texture;
253+
254+
},
255+
256+
/**
257+
* A WebGL shader/filter that can be applied to Sprites.
258+
*
259+
* @method Phaser.GameObjects.Factory#filter
260+
* @param {string} filter - The name of the filter you wish to create, for example HueRotate or SineWave.
261+
* @param {any} - Whatever parameters are needed to be passed to the filter init function.
262+
* @return {Phaser.Filter} The newly created Phaser.Filter object.
263+
*/
264+
filter: function (filter) {
265+
266+
var args = Array.prototype.slice.call(arguments, 1);
267+
268+
var filter = new Phaser.Filter[filter](this.game);
269+
270+
filter.init.apply(filter, args);
271+
272+
return filter;
273+
274+
},
275+
276+
/**
277+
* Add a new Plugin into the PluginManager.
278+
*
279+
* The Plugin must have 2 properties: `game` and `parent`. Plugin.game is set to the game reference the PluginManager uses, and parent is set to the PluginManager.
280+
*
281+
* @method Phaser.GameObjects.Factory#plugin
282+
* @param {object|Phaser.Plugin} plugin - The Plugin to add into the PluginManager. This can be a function or an existing object.
283+
* @param {...*} parameter - Additional parameters that will be passed to the Plugin.init method.
284+
* @return {Phaser.Plugin} The Plugin that was added to the manager.
285+
*/
286+
plugin: function (plugin) {
287+
288+
return this.game.plugins.add(plugin);
289+
290+
}
161291

162292
};

src/gameobjects/GameObjectCreator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Phaser.GameObjectCreator.prototype = {
4141
* @param {number} y - Y position of the image.
4242
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
4343
* @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.
44-
* @returns {Phaser.Image} the newly created sprite object.
44+
* @return {Phaser.Image} the newly created sprite object.
4545
*/
4646
image: function (x, y, key, frame) {
4747

@@ -57,7 +57,7 @@ Phaser.GameObjectCreator.prototype = {
5757
* @param {number} y - Y position of the new sprite.
5858
* @param {string|Phaser.RenderTexture|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture.
5959
* @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.
60-
* @returns {Phaser.Sprite} the newly created sprite object.
60+
* @return {Phaser.Sprite} the newly created sprite object.
6161
*/
6262
sprite: function (x, y, key, frame) {
6363

0 commit comments

Comments
 (0)