6 Replies Latest reply on Jan 5, 2011 9:32 AM by Flex harUI

    Flex 4 and lots of objects

    CannotCompute Level 1

      So here is my dilemma:

       

      I am creating map project where I have well over 4000 sprites, 5000 textfields(or labels) that are a part of an interactive map I am making. Not all maps are that big, but some of the bigger maps get to be about that size with that many objects in them.  The issue at hand is that obviously with that many objects needing to be rendered (during scaling and dragging), I run into speed/framerate issues.  My question is, what is the most efficient way to handle a project that needs to have that many objects... I have some solutions below that I have/will try, but I wanted to get some input from the experts/sudo experts .  If you have any ideas or comments please let me know and thanks in advance!

       

       

      *** Other important background ****

      I am drawing all these objects and textfields at runtime based off of a xml file that is read in. 

      I am also aware of the elastic-racetrack and have used that to help with loading and such.  The problem isn't in the loading.

       

      1. Using bitmaps instead of sprites.  The problem here is that then I need a solution to scaling. Bitmaps don't scale very nicely so zooming in would be a problem.

       

      2. I was thinking about trying to use add/remove child for objects that are not currently in the displayed area so that those object are rendering, but I think that all the calculations involved in determining whether the object is in view or not, put adding and removing tons of object all the time wouldn't really be anymore efficient.

       

      3. I know that components like the Group in flex 4 have clipAndEnable scrolling, but I am not exactly clear if that will fix the issue with not render objects that aren't in the viewport.  I have read various documentation that is conflicting so if someone can clarify that for me it would be greatly appreciated.

        • 1. Re: Flex 4 and lots of objects
          Flex harUI Adobe Employee

          Flex components use virtualization.  A DataGrid with 10000 data items only

          creates enough renderers as you can see on the screen, which might top out

          around 900 renderers (30x30 grid).  That's different than any of your

          proposed solutions in that we don't create 10000 renderers and add/remove

          the ones required, we simply re-use renderers.

          • 2. Re: Flex 4 and lots of objects
            CannotCompute Level 1

            Correct me if I am wrong, but I believe that solution works because the item is highly repeatable, meaning that item renderer takes on the same parameters for each item.  Also, will using virtualization with graphics work as well as it does with data? It seems that a lot of dataGrids(dataGroups in flex 4) are meant primarily for data (as in text), and not graphics.

            • 3. Re: Flex 4 and lots of objects
              Flex harUI Adobe Employee

              There are certainly efficiencies to be gained because the data is supposedly

              of the same format, but I would expect that each of your TextFields is

              displaying text, and each of your sprites is displaying hopefully simple

              graphics.  There might be other gains by aggregating sprites as flex 4 does

              with GraphicElements and Group.

              • 4. Re: Flex 4 and lots of objects
                CannotCompute Level 1

                Can you go into more detail on aggregating sprites as flex 4 does with GraphicElements and Group. I tried using GraphicsElements with a Group that used clipAndEnableScrolling, but that ran slower than using sprites.

                • 5. Re: Flex 4 and lots of objects
                  CannotCompute Level 1

                  I just wanted to bump this to see if anyone had any other ideas to contibute.

                  • 6. Re: Flex 4 and lots of objects
                    Flex harUI Adobe Employee

                    Flex aggregates sprites by taking sets of graphic primitives (Rect, Line,

                    etc) and drawing them into one sprite instead of one sprite per primitive.

                    It does take some code to figure out how to aggregate so it might have run

                    slower for you in some situation.

                     

                    The fundamental point is that on every frame, the player visits every Sprite

                    and TextField in existence.  If you have 10000, that's like run a for (i=0;

                    i< 10000) loop 24 times a second.  Cut that down and you should have better

                    idle time numbers, but the cost of cutting that down might be too much.