2013-08-30 03:20:14 +00:00
|
|
|
Phaser.GameObjectFactory = function (game) {
|
|
|
|
|
|
|
|
this.game = game;
|
2013-08-30 16:09:43 +00:00
|
|
|
this.world = this.game.world;
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.GameObjectFactory.prototype = {
|
|
|
|
|
|
|
|
game: null,
|
2013-08-30 16:09:43 +00:00
|
|
|
world: null,
|
2013-08-30 03:20:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Sprite with specific position and sprite sheet key.
|
|
|
|
*
|
|
|
|
* @param x {number} X position of the new sprite.
|
|
|
|
* @param y {number} Y position of the new sprite.
|
|
|
|
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
|
|
|
* @param [frame] {string|number} 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 {Sprite} The newly created sprite object.
|
|
|
|
*/
|
|
|
|
sprite: function (x, y, key, frame) {
|
|
|
|
|
2013-08-30 16:09:43 +00:00
|
|
|
return this.world.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
2013-08-30 03:20:14 +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.
|
|
|
|
*
|
|
|
|
* @param obj {object} Object the tween will be run on.
|
|
|
|
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
|
|
|
|
* @return {Phaser.Tween} The newly created tween object.
|
|
|
|
*/
|
|
|
|
tween: function (obj, localReference) {
|
|
|
|
|
|
|
|
return this.game.tweens.create(obj, localReference);
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
tileSprite: function (x, y, width, height, key, frame) {
|
|
|
|
|
|
|
|
return this.world.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-03 05:02:47 +00:00
|
|
|
text: function (x, y, text, style) {
|
|
|
|
|
|
|
|
return this.world.add(new Phaser.Text(this.game, x, y, text, style));
|
|
|
|
|
|
|
|
},
|
2013-08-30 16:09:43 +00:00
|
|
|
|
2013-09-03 00:24:16 +00:00
|
|
|
|
2013-08-30 03:20:14 +00:00
|
|
|
};
|