6 Replies Latest reply on Jun 1, 2007 7:30 PM by kglad

    Efficient way for making many enemies

    Gooms9
      Hey, i'm working on a game right now where I want around 40 or so animated enemies on screen at a time. Is this even possible with flash? Right now i'm starting to get slowdown when I have 15 or so on screen and they're not even animated yet. This is how i'm doing it at the moment.

      I'm using a setInterval function for my characters movement.
        • 1. Re: Efficient way for making many enemies
          kglad Adobe Community Professional & MVP
          if you're using flash 8, enable the cacheAsBitmap property your enemy movieclips.
          • 2. Efficient way for making many enemies
            Gooms9 Level 1
            thanks, i never knew about that property. I think the reason it was running so slow though, was that the computers at school, the ones I was testing it on are just really really horrible, and they don't even have flash player 9 which i've heard does a much better job managing resources? Anyways, i ran the same code on my home computer and I could get up to 400 enemies on screen at once with minimal slowdown. But I just wanted to make sure I'm using this right as well as deleting my onEnterFrame properly. I'm still fairly new at actionscript and even though i'm not getting any errors, I dont really know of any way to check if the last 2 lines of code in my ewalk() function are doing anything. Heres my updated code.

            Also, I found this method of adding a sprite onto the screen that seems to work and does everything I want it to, but i'm not quite sure how it works. Can anyone explain it to me? It was this line...

            enemy = attachMovie(esprite, "enemyMan", _root.getNextHighestDepth());

            Thanks!


            • 3. Re: Efficient way for making many enemies
              kglad Adobe Community Professional & MVP
              the first block of code will be a better way to do what you're trying. the 2nd block is much more efficient (only one loop), and is really what you should be using:

              • 4. Re: Efficient way for making many enemies
                kglad Adobe Community Professional & MVP
                i'm not sure what you're trying to do with that delete enemy.onEnterFrame, but that surely can't be what you want to do.

                you should use the 2nd block of code and you should remove enemy movieclip references from enemyA when the movieclip's are no longer needed.
                • 5. Re: Efficient way for making many enemies
                  Gooms9 Level 1
                  awesome! Thanks so much. I've got one more question though... I want my player to face the mouse, but for my game i've chosen a camera angle similar to starcraft, where it's a birds eye view, but on an angle. I've created a seperate movie clip for each angle that you would see the character on, but what I was wondering is would it be faster to create one movie clip with the different angles inside of it and instead of using attachMovieClip() to change the image when he's turning, use gotoAndPlay() instead?
                  • 6. Re: Efficient way for making many enemies
                    kglad Adobe Community Professional & MVP
                    there's probably not a significant difference in those two approaches.