0

I'm making a game in AS3 that requires a huge amount of bullets to be fired sequentially in an extremely short amount of time. For example, at a certain point, I need to fire one bullet, every 1-5 millisecond, for about 1 second. The game runs (smoothly) at 60 FPS with around 800+ objects on screen, but the timers don't seem to be able to tick faster than my framerate (around once every 16 milliseconds). I only have one enterFrame going, which everything else updates from.

Any tips?

Evan Ward
  • 1,371
  • 2
  • 11
  • 23
  • 1
    Check out the answer that @JasonSturges posted to one of my questions specifically discussing performance here: http://stackoverflow.com/questions/8380789/what-are-the-major-performance-hitters-in-as3-aside-from-rendering-vectors You might get some pointers to bolster the performance of your game. Something to keep in mind though is that Flash Player is not powerful enough to cater for what you're trying to do - games built in Flash have access to far less resources than your typical game in C# or similar. – Marty May 29 '12 at 05:04

2 Answers2

0

How can you possibly have 800+ objects on screen? is each object a single pixel or is the entire screen just filled? I mean to be fair I have a 1920x1080 screen in front of me so each object could be 2 pixels wide and 2 pixels tall and it wouldn't quite fill the entire screen width wise 1600x1600. I'm just curious why you would have such a scenario as I've been toying with game development a bit.

As for the technical question a Timer is not guaranteed to be triggered at the moment after the duration has expired (just some time after), it depends on how quickly it's able to get around to processing the code for the timer tick. My guess is having so many objects is exhausting the CPU (on *NIX systems use top in the console to see or in Windows use task manager is it peaking a core of the cpu?). This can probably confirm or deny it or if you turn off the creation/updating of your objects and see if the timer itself ticks at the correct rate then. If either is true it suggests the CPU is peaking out.

Consider using Stage3D to offload the object drawing to the GPU to free up the CPU to run your Timer. You may also want to consider a "game framework" like flixel to help manage your resources though I don't know that it takes advantage of the GPU... actually just Googled and found an interesting post discussing it:

http://forums.flixel.org/index.php?topic=6101.0

shaunhusain
  • 19,630
  • 4
  • 38
  • 51
  • The objects range from 5x5 to 100x100, there's a lot of overlap, look up games like Mushihimesama and Dodonpachi. I'll look into this, what you said is what I was thinking as well, wondered if there was a way around it. – Evan Ward May 29 '12 at 03:04
  • Yah I doubt you'll be able to achieve this without making use of the Stage3D classes... a couple of things to note about this it requires FP11, it requires that the GPU is accessible by said FP11 which isn't the case for all video cards... here's a tutorial http://active.tutsplus.com/tutorials/games/build-a-stage3d-shoot-em-up-full-screen-boss-battles-and-polish-tuts-premium/ and this guy has lists to some un-supported graphics cards http://www.mcfunkypants.com/2011/flash11-stage3d-tutorial-handling-init-errors/ – shaunhusain May 29 '12 at 16:36
0

The 16 milliseconds sounds about right... According to the docs it has a resolution no smaller than 16.6 seconds.

delay:Number — The delay between timer events, in milliseconds. A delay lower than 20 milliseconds is not recommended. Timer frequency is limited to 60 frames per second, meaning a delay lower than 16.6 milliseconds causes runtime problems.

I would recommend that you create x objects (bullets) off-screen, at different offsets, on each tick to get the required amount of objects you want in 1 second. This assumes that your context allows for enemies off-screen to shoot.

avanderw
  • 675
  • 1
  • 7
  • 22