forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhysicsManager.js
More file actions
92 lines (70 loc) · 2.3 KB
/
Copy pathPhysicsManager.js
File metadata and controls
92 lines (70 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var Class = require('../../utils/Class');
var GetValue = require('../../utils/object/GetValue');
var Merge = require('../../utils/object/Merge');
var NOOP = require('../../utils/NOOP');
// Physics Systems (TODO: Remove from here)
var Arcade = require('../../physics/arcade/Arcade');
var Impact = require('../../physics/impact/Impact');
var Matter = require('../../physics/matter-js/Matter');
var PhysicsManager = new Class({
initialize:
function PhysicsManager (scene)
{
this.scene = scene;
this.gameConfig = scene.sys.game.config.physics;
this.defaultSystem = scene.sys.game.config.defaultPhysicsSystem;
this.sceneConfig = scene.sys.settings.physics;
// This gets set to an instance of the physics system during boot
this.system;
// This gets set by the physics system during boot
this.world = { update: NOOP, postUpdate: NOOP, shutdown: NOOP, destroy: NOOP };
// This gets set by the physics system during boot
this.add;
},
boot: function ()
{
var sceneSystem = GetValue(this.sceneConfig, 'system', false);
if (!this.defaultSystem && !sceneSystem)
{
// No default physics system or system in this scene, so abort
return;
}
// Which physics system are we using in this Scene?
var system = (sceneSystem !== false) ? sceneSystem : this.defaultSystem;
// Create the config for it
var config = Merge(this.sceneConfig, GetValue(this.gameConfig, system, {}));
switch (system)
{
case 'arcade':
this.system = new Arcade(this, config);
break;
case 'impact':
this.system = new Impact(this, config);
break;
case 'matter':
this.system = new Matter(this, config);
break;
}
},
remove: function (object)
{
this.world.remove(object);
},
update: function (time, delta)
{
this.world.update(time, delta);
},
postUpdate: function ()
{
this.world.postUpdate();
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
module.exports = PhysicsManager;