forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightsPlugin.js
More file actions
110 lines (95 loc) · 2.75 KB
/
Copy pathLightsPlugin.js
File metadata and controls
110 lines (95 loc) · 2.75 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
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
var LightsManager = require('./LightsManager');
var PluginCache = require('../../plugins/PluginCache');
var SceneEvents = require('../../scene/events');
/**
* @classdesc
* A Scene plugin that provides a {@link Phaser.GameObjects.LightsManager} for the Light2D pipeline.
*
* Available from within a Scene via `this.lights`.
*
* Add Lights using the {@link Phaser.GameObjects.LightsManager#addLight} method:
*
* ```javascript
* // Enable the Lights Manager because it is disabled by default
* this.lights.enable();
*
* // Create a Light at [400, 300] with a radius of 200
* this.lights.addLight(400, 300, 200);
* ```
*
* For Game Objects to be affected by the Lights when rendered, you will need to set them to use the `Light2D` pipeline like so:
*
* ```javascript
* sprite.setPipeline('Light2D');
* ```
*
* @class LightsPlugin
* @extends Phaser.GameObjects.LightsManager
* @memberof Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene that this Lights Plugin belongs to.
*/
var LightsPlugin = new Class({
Extends: LightsManager,
initialize:
function LightsPlugin (scene)
{
/**
* A reference to the Scene that this Lights Plugin belongs to.
*
* @name Phaser.GameObjects.LightsPlugin#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* A reference to the Scene's systems.
*
* @name Phaser.GameObjects.LightsPlugin#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once(SceneEvents.BOOT, this.boot, this);
}
LightsManager.call(this);
},
/**
* Boot the Lights Plugin.
*
* @method Phaser.GameObjects.LightsPlugin#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on(SceneEvents.SHUTDOWN, this.shutdown, this);
eventEmitter.on(SceneEvents.DESTROY, this.destroy, this);
},
/**
* Destroy the Lights Plugin.
*
* Cleans up all references.
*
* @method Phaser.GameObjects.LightsPlugin#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.scene = undefined;
this.systems = undefined;
}
});
PluginCache.register('LightsPlugin', LightsPlugin, 'lights');
module.exports = LightsPlugin;