2017-11-09 04:01:13 +00:00
|
|
|
var ArcadeImage = require('./ArcadeImage');
|
|
|
|
var ArcadeSprite = require('./ArcadeSprite');
|
2017-11-08 17:18:41 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-11-09 15:32:08 +00:00
|
|
|
var CONST = require('./const');
|
2017-11-09 16:31:09 +00:00
|
|
|
var PhysicsGroup = require('./PhysicsGroup');
|
|
|
|
var StaticPhysicsGroup = require('./StaticPhysicsGroup');
|
2017-11-08 17:18:41 +00:00
|
|
|
|
2017-11-16 00:42:03 +00:00
|
|
|
// When registering a factory function 'this' refers to the GameObjectFactory 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
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
var Factory = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Factory (world)
|
|
|
|
{
|
|
|
|
this.world = world;
|
|
|
|
|
2017-11-09 04:01:13 +00:00
|
|
|
this.scene = world.scene;
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
this.sys = world.scene.sys;
|
2017-11-16 00:42:03 +00:00
|
|
|
|
|
|
|
// this.displayList = this.sys.
|
|
|
|
// this.displayList = sys.displayList;
|
|
|
|
// this.updateList = sys.updateList;
|
2017-11-08 17:18:41 +00:00
|
|
|
},
|
|
|
|
|
2017-11-09 17:03:58 +00:00
|
|
|
collider: function (object1, object2, collideCallback, processCallback, callbackContext)
|
|
|
|
{
|
|
|
|
return this.world.addCollider(object1, object2, collideCallback, processCallback, callbackContext);
|
|
|
|
},
|
|
|
|
|
|
|
|
overlap: function (object1, object2, collideCallback, processCallback, callbackContext)
|
|
|
|
{
|
|
|
|
return this.world.addOverlap(object1, object2, collideCallback, processCallback, callbackContext);
|
|
|
|
},
|
|
|
|
|
2018-01-08 22:11:19 +00:00
|
|
|
existing: function (gameObject, isStatic)
|
|
|
|
{
|
|
|
|
var type = (isStatic) ? CONST.STATIC_BODY : CONST.DYNAMIC_BODY;
|
|
|
|
|
|
|
|
this.world.enableBody(gameObject, type);
|
|
|
|
|
|
|
|
return gameObject;
|
|
|
|
},
|
|
|
|
|
2017-11-09 15:32:08 +00:00
|
|
|
staticImage: function (x, y, key, frame)
|
|
|
|
{
|
2017-11-09 16:31:09 +00:00
|
|
|
var image = new ArcadeImage(this.scene, x, y, key, frame);
|
2017-11-09 15:32:08 +00:00
|
|
|
|
|
|
|
this.sys.displayList.add(image);
|
|
|
|
|
2017-11-09 16:31:09 +00:00
|
|
|
this.world.enableBody(image, CONST.STATIC_BODY);
|
|
|
|
|
2017-11-09 15:32:08 +00:00
|
|
|
return image;
|
|
|
|
},
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
image: function (x, y, key, frame)
|
|
|
|
{
|
2017-11-09 16:31:09 +00:00
|
|
|
var image = new ArcadeImage(this.scene, x, y, key, frame);
|
2017-11-08 17:18:41 +00:00
|
|
|
|
|
|
|
this.sys.displayList.add(image);
|
|
|
|
|
2017-11-09 16:31:09 +00:00
|
|
|
this.world.enableBody(image, CONST.DYNAMIC_BODY);
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
return image;
|
|
|
|
},
|
|
|
|
|
2017-11-09 15:32:08 +00:00
|
|
|
staticSprite: function (x, y, key, frame)
|
|
|
|
{
|
2017-11-09 16:31:09 +00:00
|
|
|
var sprite = new ArcadeSprite(this.scene, x, y, key, frame);
|
2017-11-09 15:32:08 +00:00
|
|
|
|
|
|
|
this.sys.displayList.add(sprite);
|
|
|
|
this.sys.updateList.add(sprite);
|
|
|
|
|
2017-11-09 16:31:09 +00:00
|
|
|
this.world.enableBody(sprite, CONST.STATIC_BODY);
|
|
|
|
|
2017-11-09 15:32:08 +00:00
|
|
|
return sprite;
|
|
|
|
},
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
sprite: function (x, y, key, frame)
|
|
|
|
{
|
2017-11-09 16:31:09 +00:00
|
|
|
var sprite = new ArcadeSprite(this.scene, x, y, key, frame);
|
2017-11-08 17:18:41 +00:00
|
|
|
|
|
|
|
this.sys.displayList.add(sprite);
|
|
|
|
this.sys.updateList.add(sprite);
|
|
|
|
|
2017-11-09 16:31:09 +00:00
|
|
|
this.world.enableBody(sprite, CONST.DYNAMIC_BODY);
|
|
|
|
|
2017-11-08 17:18:41 +00:00
|
|
|
return sprite;
|
2017-11-09 04:01:13 +00:00
|
|
|
},
|
|
|
|
|
2017-11-09 16:31:09 +00:00
|
|
|
staticGroup: function (children, config)
|
|
|
|
{
|
2017-11-16 00:42:03 +00:00
|
|
|
return this.sys.updateList.add(new StaticPhysicsGroup(this.world, this.world.scene, children, config));
|
2017-11-09 16:31:09 +00:00
|
|
|
},
|
|
|
|
|
2017-11-09 04:01:13 +00:00
|
|
|
group: function (children, config)
|
|
|
|
{
|
2017-11-16 00:42:03 +00:00
|
|
|
return this.sys.updateList.add(new PhysicsGroup(this.world, this.world.scene, children, config));
|
2017-11-08 17:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Factory;
|