forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectCreator.js
More file actions
133 lines (115 loc) · 3.33 KB
/
GameObjectCreator.js
File metadata and controls
133 lines (115 loc) · 3.33 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var PluginManager = require('../boot/PluginManager');
/**
* @classdesc
* The Game Object Creator is a Scene plugin that allows you to quickly create many common
* types of Game Objects and return them. Unlike the Game Object Factory, they are not automatically
* added to the Scene.
*
* Game Objects directly register themselves with the Creator and inject their own creation
* methods into the class.
*
* @class GameObjectCreator
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object Factory belongs.
*/
var GameObjectCreator = new Class({
initialize:
function GameObjectCreator (scene)
{
/**
* The Scene to which this Game Object Creator belongs.
*
* @name Phaser.GameObjects.GameObjectCreator#scene
* @type {Phaser.Scene}
* @protected
* @since 3.0.0
*/
this.scene = scene;
/**
* A reference to the Scene.Systems.
*
* @name Phaser.GameObjects.GameObjectCreator#systems
* @type {Phaser.Scenes.Systems}
* @protected
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
/**
* A reference to the Scene Display List.
*
* @name Phaser.GameObjects.GameObjectCreator#displayList
* @type {Phaser.GameObjects.DisplayList}
* @protected
* @since 3.0.0
*/
this.displayList;
/**
* A reference to the Scene Update List.
*
* @name Phaser.GameObjects.GameObjectCreator#updateList;
* @type {Phaser.GameObjects.UpdateList}
* @protected
* @since 3.0.0
*/
this.updateList;
},
/**
* Boots the plugin.
*
* @method Phaser.GameObjects.GameObjectCreator#boot
* @private
* @since 3.0.0
*/
boot: function ()
{
this.displayList = this.systems.displayList;
this.updateList = this.systems.updateList;
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
/**
* Shuts this plugin down.
*
* @method Phaser.GameObjects.GameObjectCreator#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
},
/**
* Destroys this plugin.
*
* @method Phaser.GameObjects.GameObjectCreator#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.scene = null;
this.displayList = null;
this.updateList = null;
}
});
// Static method called directly by the Game Object creator functions
GameObjectCreator.register = function (type, factoryFunction)
{
if (!GameObjectCreator.prototype.hasOwnProperty(type))
{
GameObjectCreator.prototype[type] = factoryFunction;
}
};
PluginManager.register('GameObjectCreator', GameObjectCreator, 'make');
module.exports = GameObjectCreator;