mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Moved the depth sorting functions into the DisplayList class, as it's really the one responsible for it, not System.
This commit is contained in:
parent
98ae8009e0
commit
718859b02e
6 changed files with 46 additions and 26 deletions
|
@ -1,9 +1,10 @@
|
|||
var AlignIn = require('../display/align/in/QuickSet');
|
||||
var CONST = require('../display/align/const');
|
||||
var GetValue = require('../utils/object/GetValue');
|
||||
var NOOP = require('../utils/NOOP');
|
||||
var Zone = require('../gameobjects/zone/Zone');
|
||||
|
||||
var tempZone = new Zone({ sys: { sortChildrenFlag: false }}, 0, 0, 1, 1);
|
||||
var tempZone = new Zone({ sys: { queueDepthSort: NOOP }}, 0, 0, 1, 1);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
|
|
|
@ -121,7 +121,7 @@ var GameObject = new Class({
|
|||
this.body = null;
|
||||
|
||||
// Tell the Scene to re-sort the children
|
||||
this.scene.sys.sortChildrenFlag = true;
|
||||
this.scene.sys.queueDepthSort();
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -294,7 +294,7 @@ var GameObject = new Class({
|
|||
}
|
||||
|
||||
// Tell the Scene to re-sort the children
|
||||
this.scene.sys.sortChildrenFlag = true;
|
||||
this.scene.sys.queueDepthSort();
|
||||
|
||||
this.active = false;
|
||||
this.visible = false;
|
||||
|
|
|
@ -14,7 +14,7 @@ var Depth = {
|
|||
|
||||
set: function (value)
|
||||
{
|
||||
this.scene.sys.sortChildrenFlag = true;
|
||||
this.scene.sys.queueDepthSort();
|
||||
this._depth = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ var Transform = {
|
|||
|
||||
set: function (value)
|
||||
{
|
||||
this.scene.sys.sortChildrenFlag = true;
|
||||
this.scene.sys.queueDepthSort();
|
||||
this._depth = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ var Systems = new Class({
|
|||
this.config = config;
|
||||
this.settings = Settings.create(config);
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
|
||||
// Set by the GlobalSceneManager
|
||||
this.canvas;
|
||||
this.context;
|
||||
|
@ -157,37 +155,23 @@ var Systems = new Class({
|
|||
return;
|
||||
}
|
||||
|
||||
// inlined to avoid branching
|
||||
if (this.sortChildrenFlag)
|
||||
{
|
||||
StableSort.inplace(this.displayList.list, this.sortZ);
|
||||
var displayList = this.displayList;
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
}
|
||||
displayList.process();
|
||||
|
||||
this.cameras.render(renderer, this.displayList, interpolation);
|
||||
this.cameras.render(renderer, displayList, interpolation);
|
||||
},
|
||||
|
||||
// Force a sort of the display list on the next render
|
||||
queueDepthSort: function ()
|
||||
{
|
||||
this.sortChildrenFlag = true;
|
||||
this.displayList.queueDepthSort();
|
||||
},
|
||||
|
||||
// Immediately sorts the display list if the flag is set
|
||||
depthSort: function ()
|
||||
{
|
||||
if (this.sortChildrenFlag)
|
||||
{
|
||||
StableSort.inplace(this.displayList.list, this.sortZ);
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
}
|
||||
},
|
||||
|
||||
sortZ: function (childA, childB)
|
||||
{
|
||||
return childA._depth - childB._depth;
|
||||
this.displayList.depthSort();
|
||||
},
|
||||
|
||||
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var StableSort = require('../../utils/array/StableSort');
|
||||
|
||||
var DisplayList = new Class({
|
||||
|
||||
|
@ -13,9 +14,43 @@ var DisplayList = new Class({
|
|||
// The equivalent of the old `Sprite.children` array.
|
||||
this.list = [];
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
|
||||
this.position = 0;
|
||||
},
|
||||
|
||||
process: function ()
|
||||
{
|
||||
if (this.sortChildrenFlag)
|
||||
{
|
||||
StableSort.inplace(this.list, this.sortZ);
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
}
|
||||
},
|
||||
|
||||
sortZ: function (childA, childB)
|
||||
{
|
||||
return childA._depth - childB._depth;
|
||||
},
|
||||
|
||||
// Force a sort of the display list on the next call to process
|
||||
queueDepthSort: function ()
|
||||
{
|
||||
this.sortChildrenFlag = true;
|
||||
},
|
||||
|
||||
// Immediately sorts the display list if the flag is set
|
||||
depthSort: function ()
|
||||
{
|
||||
if (this.sortChildrenFlag)
|
||||
{
|
||||
StableSort.inplace(this.list, this.sortZ);
|
||||
|
||||
this.sortChildrenFlag = false;
|
||||
}
|
||||
},
|
||||
|
||||
add: function (child)
|
||||
{
|
||||
// Is child already in this display list?
|
||||
|
|
Loading…
Add table
Reference in a new issue