forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayList.js
More file actions
166 lines (143 loc) · 4.08 KB
/
Copy pathDisplayList.js
File metadata and controls
166 lines (143 loc) · 4.08 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* @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 List = require('../structs/List');
var PluginManager = require('../boot/PluginManager');
var StableSort = require('../utils/array/StableSort');
/**
* @classdesc
* [description]
*
* @class DisplayList
* @extends Phaser.Structs.List.<Phaser.GameObjects.GameObject>
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var DisplayList = new Class({
Extends: List,
initialize:
function DisplayList (scene)
{
List.call(this, scene);
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#sortChildrenFlag
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.sortChildrenFlag = false;
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* [description]
*
* @name Phaser.GameObjects.DisplayList#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
if (!scene.sys.settings.isBooted)
{
scene.sys.events.once('boot', this.boot, this);
}
},
/**
* [description]
*
* @method Phaser.GameObjects.DisplayList#boot
* @since 3.0.0
*/
boot: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.on('shutdown', this.shutdown, this);
eventEmitter.on('destroy', this.destroy, this);
},
/**
* Force a sort of the display list on the next call to depthSort.
*
* @method Phaser.GameObjects.DisplayList#queueDepthSort
* @since 3.0.0
*/
queueDepthSort: function ()
{
this.sortChildrenFlag = true;
},
/**
* Immediately sorts the display list if the flag is set.
*
* @method Phaser.GameObjects.DisplayList#depthSort
* @since 3.0.0
*/
depthSort: function ()
{
if (this.sortChildrenFlag)
{
StableSort.inplace(this.list, this.sortByDepth);
this.sortChildrenFlag = false;
}
},
/**
* [description]
*
* @method Phaser.GameObjects.DisplayList#sortByDepth
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} childA - [description]
* @param {Phaser.GameObjects.GameObject} childB - [description]
*
* @return {integer} [description]
*/
sortByDepth: function (childA, childB)
{
return childA._depth - childB._depth;
},
/**
* Given an array of Game Objects, sort the array and return it,
* so that the objects are in index order with the lowest at the bottom.
*
* @method Phaser.GameObjects.DisplayList#sortGameObjects
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject[]} gameObjects - [description]
*
* @return {array} [description]
*/
sortGameObjects: function (gameObjects)
{
if (gameObjects === undefined) { gameObjects = this.list; }
this.scene.sys.depthSort();
return gameObjects.sort(this.sortIndexHandler.bind(this));
},
/**
* Note that the given array is sorted in place, even though it isn't returned directly it will still be updated.
*
* @method Phaser.GameObjects.DisplayList#getTopGameObject
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject[]} gameObjects - [description]
*
* @return {Phaser.GameObjects.GameObject} The top-most Game Object on the Display List.
*/
getTopGameObject: function (gameObjects)
{
this.sortGameObjects(gameObjects);
return gameObjects[gameObjects.length - 1];
}
});
PluginManager.register('DisplayList', DisplayList, 'displayList');
module.exports = DisplayList;