addToScene added to all Game Object Creators

This commit is contained in:
Richard Davey 2018-05-02 10:57:26 +01:00
parent a30d5acb9e
commit 28251fd0f5
14 changed files with 108 additions and 43 deletions

View file

@ -43,6 +43,7 @@ The Loader has been given a slight overhaul to improve its performance and exten
* The BaseCache has a new method `exists` that will return a boolean if an entry for the given key exists in the cache or not.
* ScenePlugin.getIndex will return the index of the given Scene in the Scene List.
* The Scene Systems will emit a `ready` event when it has fully finished starting up and all plugins are available. Re: #3636 (thanks @Yazir)
* All Game Object Creators now have an extra boolean argument `addToScene`. If you set this to `true` it will add the Game Object being created to the Scene automatically, while `false` will do the opposite, i.e.: `this.make.image(config, false)`. You can still specify the `add` property in the Config object too, but if the argument is provided it will override the property.
### Bug Fixes
@ -61,6 +62,7 @@ The Loader has been given a slight overhaul to improve its performance and exten
* Emitter.setEmitZone was rejecting custom objects passed as the source argument because it was checking for the wrong methods (thanks @samme)
* ScenePlugin.setActive would only toggle the current Scene, not any given Scene.
* ScenePlugin.setVisible would only toggle the current Scene, not any given Scene.
* The Graphics Creator would automatically add the Graphics to the display list by mistake. The default should be to remain hidden. Fix #3637 (thanks @mikuso)
### Examples, Documentation and TypeScript

View file

@ -27,11 +27,12 @@ var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
* @method Phaser.GameObjects.GameObjectCreator#dynamicBitmapText
* @since 3.0.0
*²
* @param {BitmapTextConfig} config - [description]
* @param {BitmapTextConfig} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.DynamicBitmapText} The Game Object that was created.
*/
GameObjectCreator.register('dynamicBitmapText', function (config)
GameObjectCreator.register('dynamicBitmapText', function (config, addToScene)
{
var font = GetAdvancedValue(config, 'font', '');
var text = GetAdvancedValue(config, 'text', '');
@ -40,6 +41,11 @@ GameObjectCreator.register('dynamicBitmapText', function (config)
var bitmapText = new BitmapText(this.scene, 0, 0, font, text, size, align);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, bitmapText, config);
return bitmapText;

View file

@ -18,11 +18,12 @@ var GetValue = require('../../../utils/object/GetValue');
* @method Phaser.GameObjects.GameObjectCreator#bitmapText
* @since 3.0.0
*
* @param {BitmapTextConfig} config - [description]
*
* @param {BitmapTextConfig} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.BitmapText} The Game Object that was created.
*/
GameObjectCreator.register('bitmapText', function (config)
GameObjectCreator.register('bitmapText', function (config, addToScene)
{
var font = GetValue(config, 'font', '');
var text = GetAdvancedValue(config, 'text', '');
@ -32,6 +33,11 @@ GameObjectCreator.register('bitmapText', function (config)
var bitmapText = new BitmapText(this.scene, 0, 0, font, text, size);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, bitmapText, config);
return bitmapText;

View file

@ -17,17 +17,23 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
* @method Phaser.GameObjects.GameObjectCreator#blitter
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Blitter} The Game Object that was created.
*/
GameObjectCreator.register('blitter', function (config)
GameObjectCreator.register('blitter', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var blitter = new Blitter(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, blitter, config);
return blitter;

View file

@ -18,17 +18,23 @@ var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
* @method Phaser.GameObjects.GameObjectCreator#container
* @since 3.4.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Container} The Game Object that was created.
*/
GameObjectCreator.register('container', function (config)
GameObjectCreator.register('container', function (config, addToScene)
{
var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0);
var container = new Container(this.scene, x, y);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, container, config);
return container;

View file

@ -17,17 +17,23 @@ var Image = require('./Image');
* @method Phaser.GameObjects.GameObjectCreator#image
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Image} The Game Object that was created.
*/
GameObjectCreator.register('image', function (config)
GameObjectCreator.register('image', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var image = new Image(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, image, config);
return image;

View file

@ -18,11 +18,12 @@ var Mesh = require('./Mesh');
* @method Phaser.GameObjects.GameObjectCreator#mesh
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Mesh} The Game Object that was created.
*/
GameObjectCreator.register('mesh', function (config)
GameObjectCreator.register('mesh', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
@ -33,6 +34,11 @@ GameObjectCreator.register('mesh', function (config)
var mesh = new Mesh(this.scene, 0, 0, vertices, uv, colors, alphas, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, mesh, config);
return mesh;

View file

@ -17,11 +17,12 @@ var ParticleEmitterManager = require('./ParticleEmitterManager');
* @method Phaser.GameObjects.GameObjectCreator#particles
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} The Game Object that was created.
*/
GameObjectCreator.register('particles', function (config)
GameObjectCreator.register('particles', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
@ -30,6 +31,11 @@ GameObjectCreator.register('particles', function (config)
// frame is optional and can contain the emitters array or object if skipped
var manager = new ParticleEmitterManager(this.scene, key, frame, emitters);
if (addToScene !== undefined)
{
config.add = addToScene;
}
var add = GetFastValue(config, 'add', false);
if (add)
@ -41,11 +47,3 @@ GameObjectCreator.register('particles', function (config)
return manager;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
// this.displayList - a reference to the Display List the Scene owns
// this.updateList - a reference to the Update List the Scene owns

View file

@ -17,11 +17,12 @@ var Quad = require('./Quad');
* @method Phaser.GameObjects.GameObjectCreator#quad
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Quad} The Game Object that was created.
*/
GameObjectCreator.register('quad', function (config)
GameObjectCreator.register('quad', function (config, addToScene)
{
var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0);
@ -30,9 +31,12 @@ GameObjectCreator.register('quad', function (config)
var quad = new Quad(this.scene, x, y, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, quad, config);
return quad;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -26,18 +26,25 @@ var RenderTexture = require('./RenderTexture');
* @method Phaser.GameObjects.GameObjectCreator#renderTexture
* @since 3.2.0
*
* @param {RenderTextureConfig} config - [description]
* @param {RenderTextureConfig} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.RenderTexture} The Game Object that was created.
*/
GameObjectCreator.register('renderTexture', function (config)
GameObjectCreator.register('renderTexture', function (config, addToScene)
{
var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0);
var width = GetAdvancedValue(config, 'width', 32);
var height = GetAdvancedValue(config, 'height', 32);
var renderTexture = new RenderTexture(this.scene, x, y, width, height);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, renderTexture, config);
return renderTexture;

View file

@ -18,26 +18,28 @@ var Sprite = require('./Sprite');
* @method Phaser.GameObjects.GameObjectCreator#sprite
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Sprite} The Game Object that was created.
*/
GameObjectCreator.register('sprite', function (config)
GameObjectCreator.register('sprite', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var sprite = new Sprite(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, sprite, config);
// Sprite specific config options:
BuildGameObjectAnimation(sprite, config);
// Physics, Input, etc to follow ...
return sprite;
});
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -18,25 +18,29 @@ var Sprite3D = require('./Sprite3D');
* @method Phaser.GameObjects.GameObjectCreator#sprite3D
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Sprite3D} The Game Object that was created.
*/
GameObjectCreator.register('sprite3D', function (config)
GameObjectCreator.register('sprite3D', function (config, addToScene)
{
var key = GetAdvancedValue(config, 'key', null);
var frame = GetAdvancedValue(config, 'frame', null);
var sprite = new Sprite3D(this.scene, 0, 0, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, sprite, config);
// Sprite specific config options:
BuildGameObjectAnimation(sprite, config);
// Physics, Input, etc to follow ...
return sprite;
});

View file

@ -17,11 +17,12 @@ var Text = require('./Text');
* @method Phaser.GameObjects.GameObjectCreator#text
* @since 3.0.0
*
* @param {object} config - [description]
* @param {object} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Text} The Game Object that was created.
*/
GameObjectCreator.register('text', function (config)
GameObjectCreator.register('text', function (config, addToScene)
{
// style Object = {
// font: [ 'font', '16px Courier' ],
@ -60,6 +61,11 @@ GameObjectCreator.register('text', function (config)
var text = new Text(this.scene, 0, 0, content, style);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, text, config);
// Text specific config options:

View file

@ -29,11 +29,12 @@ var TileSprite = require('./TileSprite');
* @method Phaser.GameObjects.GameObjectCreator#tileSprite
* @since 3.0.0
*
* @param {TileSprite} config - [description]
* @param {TileSprite} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.TileSprite} The Game Object that was created.
*/
GameObjectCreator.register('tileSprite', function (config)
GameObjectCreator.register('tileSprite', function (config, addToScene)
{
var x = GetAdvancedValue(config, 'x', 0);
var y = GetAdvancedValue(config, 'y', 0);
@ -44,6 +45,11 @@ GameObjectCreator.register('tileSprite', function (config)
var tile = new TileSprite(this.scene, x, y, width, height, key, frame);
if (addToScene !== undefined)
{
config.add = addToScene;
}
BuildGameObject(this.scene, tile, config);
return tile;