BBGamelib.CCNode.sortAllChildren C# (CSharp) Method

sortAllChildren() protected method

protected sortAllChildren ( ) : void
return void
		protected virtual void sortAllChildren()
		{
			if (_isReorderChildDirty)
			{
				CCNode[] x = _children.ToArray();
				int i,j,length = x.Length;
				CCNode tempItem;
				
				// insertion sort
				for(i=1; i<length; i++)
				{
					tempItem = x[i];
					j = i-1;
					
					//continue moving element downwards while zOrder is smaller or when zOrder is the same but mutatedIndex is smaller
					while(j>=0 && ( tempItem.zOrder < x[j].zOrder || ( tempItem.zOrder== x[j].zOrder && tempItem.orderOfArrival < x[j].orderOfArrival ) ) )
					{
						x[j+1] = x[j];
						j = j-1;
					}
					x[j+1] = tempItem;
				}

				_children = x.OfType<CCNode>().ToList();

				//don't need to check children recursively, that's done in visit of each child
				
				_isReorderChildDirty = false;
			}
		}
		#endregion