2018-01-17 03:41:58 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Factory = require('./Factory');
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var Merge = require('../../utils/object/Merge');
|
|
|
|
var PluginManager = require('../../plugins/PluginManager');
|
|
|
|
var World = require('./World');
|
|
|
|
|
|
|
|
// Phaser.Physics.Arcade.ArcadePhysics
|
|
|
|
|
|
|
|
var ArcadePhysics = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function ArcadePhysics (scene)
|
|
|
|
{
|
|
|
|
// The Scene that owns this plugin
|
|
|
|
this.scene = scene;
|
|
|
|
|
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
if (!scene.sys.settings.isBooted)
|
|
|
|
{
|
|
|
|
scene.sys.events.once('boot', this.boot, this);
|
|
|
|
}
|
2018-01-17 03:41:58 +00:00
|
|
|
|
|
|
|
this.config = this.getConfig();
|
|
|
|
|
|
|
|
this.world;
|
|
|
|
|
|
|
|
this.add;
|
|
|
|
},
|
|
|
|
|
|
|
|
getConfig: function ()
|
|
|
|
{
|
|
|
|
var gameConfig = this.systems.game.config.physics;
|
|
|
|
var sceneConfig = this.systems.settings.physics;
|
|
|
|
|
|
|
|
var config = Merge(
|
|
|
|
GetFastValue(sceneConfig, 'arcade', {}),
|
|
|
|
GetFastValue(gameConfig, 'arcade', {})
|
|
|
|
);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.world = new World(this.scene, this.config);
|
|
|
|
this.add = new Factory(this.world);
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
|
|
|
eventEmitter.on('update', this.world.update, this.world);
|
|
|
|
eventEmitter.on('postupdate', this.world.postUpdate, this.world);
|
|
|
|
eventEmitter.on('shutdown', this.shutdown, this);
|
|
|
|
eventEmitter.on('destroy', this.destroy, this);
|
2018-01-17 03:41:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
overlap: function (object1, object2, overlapCallback, processCallback, callbackContext)
|
|
|
|
{
|
|
|
|
if (overlapCallback === undefined) { overlapCallback = null; }
|
|
|
|
if (processCallback === undefined) { processCallback = null; }
|
|
|
|
if (callbackContext === undefined) { callbackContext = overlapCallback; }
|
|
|
|
|
|
|
|
return this.world.collideObjects(object1, object2, overlapCallback, processCallback, callbackContext, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
collide: function (object1, object2, collideCallback, processCallback, callbackContext)
|
|
|
|
{
|
|
|
|
if (collideCallback === undefined) { collideCallback = null; }
|
|
|
|
if (processCallback === undefined) { processCallback = null; }
|
|
|
|
if (callbackContext === undefined) { callbackContext = collideCallback; }
|
|
|
|
|
|
|
|
return this.world.collideObjects(object1, object2, collideCallback, processCallback, callbackContext, false);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Utils
|
|
|
|
accelerateTo: require('./utils/AccelerateTo'),
|
|
|
|
accelerateToObject: require('./utils/AccelerateToObject'),
|
|
|
|
closest: require('./utils/Closest'),
|
|
|
|
furthest: require('./utils/Furthest'),
|
|
|
|
moveTo: require('./utils/MoveTo'),
|
|
|
|
moveToObject: require('./utils/MoveToObject'),
|
|
|
|
velocityFromAngle: require('./utils/VelocityFromAngle'),
|
|
|
|
velocityFromRotation: require('./utils/VelocityFromRotation'),
|
|
|
|
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
|
|
|
this.world.shutdown();
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.world.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-18 05:18:09 +00:00
|
|
|
PluginManager.register('ArcadePhysics', ArcadePhysics, 'arcadePhysics');
|
2018-01-17 03:41:58 +00:00
|
|
|
|
|
|
|
module.exports = ArcadePhysics;
|