예제 #1
0
        //override sortAllChildren
        public override void SortAllChildren()
        {
            if (m_bReorderChildDirty)
            {
                int      j = 0, count = m_pChildren.count;
                CCNode[] elements = m_pChildren.Elements;
                // CCNode tempItem;

                //insertion sort - change to qsort per RIQ
                CCNode.Quicksort(elements, 0, count - 1);

                /*
                 * for (int i = 1; i < count; i++)
                 * {
                 *  tempItem = elements[i];
                 *  j = i - 1;
                 *
                 *  //continue moving element downwards while zOrder is smaller or when zOrder is the same but orderOfArrival is smaller
                 *  while (j >= 0 &&
                 *         (tempItem.m_nZOrder < elements[j].m_nZOrder ||
                 *          (tempItem.m_nZOrder == elements[j].m_nZOrder && tempItem.m_uOrderOfArrival < elements[j].m_uOrderOfArrival)))
                 *  {
                 *      elements[j + 1] = elements[j];
                 *      j--;
                 *  }
                 *
                 *  elements[j + 1] = tempItem;
                 * }
                 */

                //sorted now check all children
                if (count > 0)
                {
                    //first sort all children recursively based on zOrder
                    for (int i = 0; i < count; i++)
                    {
                        elements[i].SortAllChildren();
                    }

                    int index = 0;

                    //fast dispatch, give every child a new atlasIndex based on their relative zOrder (keep parent -> child relations intact)
                    // and at the same time reorder descedants and the quads to the right index
                    for (int i = 0; i < count; i++)
                    {
                        UpdateAtlasIndex((CCSprite)elements[i], ref index);
                    }
                }

                m_bReorderChildDirty = false;
            }
        }
예제 #2
0
        public override void SortAllChildren()
        {
            if (m_bReorderChildDirty)
            {
                int      i, j, length = m_pChildren.count;
                CCNode[] x = m_pChildren.Elements;
//                CCNode tempItem;

                CCNode.Quicksort(x, 0, length - 1);

                /*
                 * // 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 orderOfArrival is smaller
                 *  while (j >= 0 &&
                 *         (tempItem.m_nZOrder < x[j].m_nZOrder ||
                 *          (tempItem.m_nZOrder == x[j].m_nZOrder && tempItem.m_uOrderOfArrival < x[j].m_uOrderOfArrival)))
                 *  {
                 *      x[j + 1] = x[j];
                 *      j = j - 1;
                 *  }
                 *  x[j + 1] = tempItem;
                 * }
                 */

                if (m_pobBatchNode != null)
                {
                    foreach (CCNode node in m_pChildren)
                    {
                        (node).SortAllChildren();
                    }
                }

                m_bReorderChildDirty = false;
            }
        }