Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:21:20+00:00 2026-05-28T19:21:20+00:00

I’m trying to pre-sort an array of items are added into an array using

  • 0

I’m trying to pre-sort an array of items are added into an array using the following:

draw(texture:LTexture, position:Point, depth:int = 0):void

At the moment, calling this adds the texture into a queue. Once the items in my queue are ready to be rendered, I use the following to sort my array:

queue.sortOn("depth");

This works fine, but it’s slow, especially when my queue has over 2000 textures to be drawn.


I’m trying to presort my array by adding some new logic into draw(). Basically my queue is now a 2D array, where the first layer represents depth and each array within this contains the textures to draw. For example:

queue[1] = [texture, texture];
queue[4] = [texture];
queue[2] = [texture, texture, texture, texture];

I then have a function which combines these arrays into a new queue:

function collate():Array
{
    var collated:Array = [];

    for each(var i:Array in _block)
        collated = collated.concat(i);

    return collated;
}

This seems to work ok, but there are a few issues so far:

  1. When I use vastly varying depths, e.g. 5 and 17, the foreach loop seems to concatenate my inner arrays in whichever order they were created, rather than by their index (weird – works fine if I use depths closer together).
  2. If the depths specified are really high and/or greatly varied, my queue ends up having a tonne of empty slots that my foreach loop will have to include in the process of iteration when concatenating my arrays, eg: ,,,,,,,,,,,texture2,texture3,,,,,,texture0,texture1,,,,,texture4

How can I better approach what I am trying to achieve? That being, I want to end up with an array containing all of my textures sorted by depth.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:21:21+00:00Added an answer on May 28, 2026 at 7:21 pm

    Although I can’t imagine a reason to have 2000 textures to be z-sorted (seems like an awful lot), I came up with these ideas:

    1. Use a linked list instead of an array, and have the textures find their respective positions at the time you add them (add() each new texture to the first node, then let the linked nodes pass it on until it reaches its place at the correct depth).

      If you have the time to get into linked lists, this is probably the solution I would choose, because it allows you to keep existing structures and add or remove textures as they come along, without having to sort the entire list again and again.

    2. You can combine linked list with a dictionary: Create a linked list as described above and collect references to the first node of each depth in a Dictionary (node_dictionary[depth] = node;). That way, you can add() new nodes at a given depth, instead of having to pass them on from the beginning of the list.

    3. Use a second array to collect only your existing queue indices (push the index each time you add a texture) and sort that simple array to get rid of the empty slots.

      var index_array : Array = [];
      ...
      queue[17].push(texture);
      index_array.push (17);
      ...
      queue[1].push(texture);
      index_array.push (1);
      ...
      queue[17].push(texture); // probably more than one texture for each index
      index_array.push (17);
      
      index_array.sort(Array.NUMERIC|Array.UNIQUESORT);
      
      var i:int = -1;
      while (++i < index_array.length) drawTextures(queue[i]);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.