2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
Phaser.GameObjectFactory = function (game) {
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
this.game = game;
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.World} world - A reference to the game world.
|
|
|
|
*/
|
2013-08-30 16:09:43 +00:00
|
|
|
this.world = this.game.world;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.GameObjectFactory.prototype = {
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - A reference to the currently running Game.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 03:20:14 +00:00
|
|
|
game: null,
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.World} world - A reference to the game world.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-08-30 16:09:43 +00:00
|
|
|
world: null,
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
* @method existing.
|
|
|
|
* @param {object} - Description.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean} Description.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-10 23:35:21 +00:00
|
|
|
existing: function (object) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(object);
|
2013-09-10 23:35:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
/**
|
|
|
|
* Create a new Sprite with specific position and sprite sheet key.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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.
|
2013-08-30 03:20:14 +00:00
|
|
|
*/
|
2013-09-11 02:55:53 +00:00
|
|
|
sprite: function (x, y, key, frame) {
|
2013-08-30 03:20:14 +00:00
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.create(x, y, key, frame);
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-04 20:03:39 +00:00
|
|
|
/**
|
2013-09-06 19:20:58 +00:00
|
|
|
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
|
2013-09-04 20:03:39 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method child
|
2013-10-04 15:51:24 +00:00
|
|
|
* @param {Phaser.Group} group - The Group to add this child to.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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.
|
2013-09-04 20:03:39 +00:00
|
|
|
*/
|
2013-10-04 15:51:24 +00:00
|
|
|
child: function (group, x, y, key, frame) {
|
2013-09-04 20:03:39 +00:00
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return group.create(x, y, key, frame);
|
|
|
|
|
2013-09-04 20:03:39 +00:00
|
|
|
},
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
/**
|
|
|
|
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @method tween
|
|
|
|
* @param {object} obj - Object the tween will be run on.
|
|
|
|
* @return {Description} Description.
|
2013-08-30 16:09:43 +00:00
|
|
|
*/
|
2013-09-11 01:57:36 +00:00
|
|
|
tween: function (obj) {
|
2013-08-30 16:09:43 +00:00
|
|
|
|
2013-09-11 01:57:36 +00:00
|
|
|
return this.game.tweens.create(obj);
|
2013-08-30 16:09:43 +00:00
|
|
|
|
2013-09-03 00:24:16 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method group
|
|
|
|
* @param {Description} parent - Description.
|
|
|
|
* @param {Description} name - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-06 19:20:58 +00:00
|
|
|
group: function (parent, name) {
|
|
|
|
|
|
|
|
return new Phaser.Group(this.game, parent, name);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method audio
|
|
|
|
* @param {Description} key - Description.
|
|
|
|
* @param {Description} volume - Description.
|
|
|
|
* @param {Description} loop - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-03 00:24:16 +00:00
|
|
|
audio: function (key, volume, loop) {
|
|
|
|
|
|
|
|
return this.game.sound.add(key, volume, loop);
|
|
|
|
|
2013-09-03 02:19:42 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-09-03 02:19:42 +00:00
|
|
|
tileSprite: function (x, y, width, height, key, frame) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
|
2013-09-03 02:19:42 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method text
|
|
|
|
* @param {Description} x - Description.
|
|
|
|
* @param {Description} y - Description.
|
|
|
|
* @param {Description} text - Description.
|
|
|
|
* @param {Description} style - Description.
|
|
|
|
*/
|
2013-09-03 05:02:47 +00:00
|
|
|
text: function (x, y, text, style) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
|
2013-09-03 05:02:47 +00:00
|
|
|
|
|
|
|
},
|
2013-08-30 16:09:43 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-09-08 23:30:44 +00:00
|
|
|
button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
|
2013-09-08 23:30:44 +00:00
|
|
|
|
|
|
|
},
|
2013-09-03 00:24:16 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method graphics
|
|
|
|
* @param {Description} x - Description.
|
|
|
|
* @param {Description} y - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-09 16:01:59 +00:00
|
|
|
graphics: function (x, y) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(new Phaser.Graphics(this.game, x, y));
|
2013-09-09 16:01:59 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method emitter
|
|
|
|
* @param {Description} x - Description.
|
|
|
|
* @param {Description} y - Description.
|
|
|
|
* @param {Description} maxParticles - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-10 10:09:25 +00:00
|
|
|
emitter: function (x, y, maxParticles) {
|
|
|
|
|
|
|
|
return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method bitmapText
|
|
|
|
* @param {Description} x - Description.
|
|
|
|
* @param {Description} y - Description.
|
|
|
|
* @param {Description} text - Description.
|
|
|
|
* @param {Description} style - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-10 22:51:35 +00:00
|
|
|
bitmapText: function (x, y, text, style) {
|
|
|
|
|
2013-10-04 15:51:24 +00:00
|
|
|
return this.world.add(new Phaser.BitmapText(this.game, x, y, text, style));
|
2013-09-10 22:51:35 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method tilemap
|
|
|
|
* @param {Description} key - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-10-16 05:33:39 +00:00
|
|
|
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) {
|
2013-09-12 03:24:01 +00:00
|
|
|
|
2013-10-16 05:33:39 +00:00
|
|
|
return this.world.add(new Phaser.TilemapLayer(this.game, x, y, width, height, tileset, tilemap, layer));
|
2013-09-12 03:24:01 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* Description.
|
|
|
|
*
|
|
|
|
* @method renderTexture
|
|
|
|
* @param {Description} key - Description.
|
|
|
|
* @param {Description} width - Description.
|
|
|
|
* @param {Description} height - Description.
|
|
|
|
* @return {Description} Description.
|
|
|
|
*/
|
2013-09-11 01:57:36 +00:00
|
|
|
renderTexture: function (key, width, height) {
|
|
|
|
|
|
|
|
var texture = new Phaser.RenderTexture(this.game, key, width, height);
|
|
|
|
|
|
|
|
this.game.cache.addRenderTexture(key, texture);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|