Removed 'group' / 'parent' argument and forced to the State children component. You should use 'make' if you wish to add elsewhere.

This commit is contained in:
Richard Davey 2017-04-04 23:58:33 +01:00
parent f79dcd0a07
commit 8ec9061b43
10 changed files with 15 additions and 30 deletions

View file

@ -12,20 +12,14 @@ var factories = {};
var FactoryContainer = function ()
{
// console.log('FactoryContainer is alive');
this.register = function (factory)
{
if (factories.hasOwnProperty(factory.KEY))
{
// console.log('Already registered', factory.KEY);
return this.getType(factory.KEY);
}
else
{
// console.log('registering', factory.KEY);
factories[factory.KEY] = {
add: factory.add,
make: factory.make
@ -46,8 +40,6 @@ var FactoryContainer = function ()
{
if (factories.hasOwnProperty(factory))
{
// console.log('Loading', factory);
dest[factory] = (isFactory) ? factories[factory].add : factories[factory].make;
}
}

View file

@ -7,7 +7,7 @@ var DynamicBitmapTextFactory = {
add: function (x, y, font, text, size, align)
{
return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align));
return this.children.add(new BitmapText(this.state, x, y, font, text, size, align));
},
make: function (x, y, font, text, size, align)

View file

@ -7,7 +7,7 @@ var BitmapTextFactory = {
add: function (x, y, font, text, size, align)
{
return this.state.children.add(new BitmapText(this.state, x, y, font, text, size, align));
return this.children.add(new BitmapText(this.state, x, y, font, text, size, align));
},
make: function (x, y, font, text, size, align)

View file

@ -6,11 +6,9 @@ var BlitterFactory = {
KEY: 'blitter',
add: function (x, y, key, frame, parent)
add: function (x, y, key, frame)
{
if (parent === undefined) { parent = this.state; }
return parent.children.add(new Blitter(this.state, x, y, key, frame));
return this.children.add(new Blitter(this.state, x, y, key, frame));
},
make: function (x, y, key, frame)

View file

@ -7,7 +7,7 @@ var GraphicsFactory = {
add: function (options)
{
return this.state.children.add(new Graphics(this.state, options));
return this.children.add(new Graphics(this.state, options));
},
make: function (options)

View file

@ -22,11 +22,9 @@ var ImageFactory = {
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Image} The newly created Image object.
*/
add: function (x, y, key, frame, parent)
add: function (x, y, key, frame)
{
if (parent === undefined) { parent = this.state; }
return parent.children.add(new Image(this.state, x, y, key, frame));
return this.children.add(new Image(this.state, x, y, key, frame));
},
make: function (x, y, key, frame)

View file

@ -26,20 +26,13 @@ var SpriteFactory = {
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Sprite} The newly created Sprite object.
*/
add: function (x, y, key, frame, group)
add: function (x, y, key, frame)
{
if (group === undefined) { group = this.state; }
// console.log('ImageFactory.add', key, x, y, frame, group);
// console.log('into State', this.state);
return group.children.add(new Sprite(this.state, x, y, key, frame));
return this.children.add(new Sprite(this.state, x, y, key, frame));
},
make: function (x, y, key, frame)
{
// console.log('ImageFactory.make', key, x, y, frame);
return new Sprite(this.state, x, y, key, frame);
}

View file

@ -7,7 +7,7 @@ var TextFactory = {
add: function (x, y, text, style)
{
return this.state.children.add(new Text(this.state, x, y, text, style));
return this.children.add(new Text(this.state, x, y, text, style));
},
make: function (x, y, text, style)

View file

@ -17,6 +17,8 @@ var GameObjectCreator = function (state)
{
this.state = state;
this.children = state.sys.children;
FactoryContainer.load(this, false);
};

View file

@ -17,6 +17,8 @@ var GameObjectFactory = function (state)
{
this.state = state;
this.children = state.sys.children;
FactoryContainer.load(this, true);
};
@ -26,7 +28,7 @@ GameObjectFactory.prototype = {
existing: function (child)
{
return this.state.children.add(child);
return this.children.add(child);
},
destroy: function ()