1 Reply Latest reply on Mar 2, 2007 7:19 AM by MotionMaker

    Managing large arrays

      Im creating a game that enemies come on to the stage that you shoot at. The enemies and shots are attached into arrays and everytime a instance of eather the "enemy" or "shot" comes onto the stage the array gets another attached to the bottom of the array so it never runs out.
      After the enemy "dies" or the shot exits the stage it gets deleted but the array "slot" just turns to undefined so after a bit these arrays get large. I'm then doing a hit test of every shot to every enemy in a loop. So when these 2 arrays get large, even if undefined the frame rate drops to nearly 0.
      Each "enemy" has 5 other matching arrays with it for speed, health,experience,money, and damage and I'm wondering how to make these Arrays small enough to run properly or a better way to create this with the same results.
        • 1. Re: Managing large arrays
          MotionMaker Level 1
          Look at Array.splice.

          If the array element is the only reference to the clip, the clip should be cleaned up by the garbage collector. However if there is another reference and it was created with createEmptyMovieClip, duplicateMovieClip or attachMovie, you can use
          MovieClip.removeMovieClip in addition to removing the array element. Still I like to be sure all variable references to a clip are set undefined as well.

          However if you are storing the index in other arrays or variables, you have to adjust those and thus a looped approach might be considered where you loop until you hit the one to delete, then you copy the index element +1 to the current loop index. Then use Array.pop to remove the last index.