Tips for optimizing for Flash Export
Hi all,
I'm tring to convert an old game to run in Flash and have managed to get it working BUT the frame rate is appauling. (Not blamnig MMF mind you) It should be noted this exact same game keeps a solid 50 FPS easily as a PC runtime.
The game is at 640x480 with 3 layers of scrolling and maybe 40 to 60 active objects in a frame.
I'm hoping to get the game to run a solid 12 FPS without gutting everything out.
Does anyone have experience with what changes, cuts or general event making habbits will give me back the most frames per second?
For instance:
1) Not using fine collision detection.
2) Eliminating layers of scrolling.
Other ideas?
Does lowering the color depth change anything in Flash?
Does avoiding using alpha chaneled images (loading in as indexed PNG's with only one transparent color...no semitransparent pixcels)save anything on frame rate?
Any suggestions and reports on personal experience would be greatly apreciated.
thanks
Re: Tips for optimizing for Flash Export
Try getting rid of the layers for a start - I think that's probably your biggest speed killer. I would try dragging the main gameplay layer down to layer 1, making the other layers invisible, and see what difference that makes.
Of your other options, I know that colour depth won't make a difference (it's exported the same way whichever option you choose).
Re: Tips for optimizing for Flash Export
I noticed something that is making the bad frame rate seem infinately worse. Its the fact that its remembering ALL of my button presses, no matter how long ago they were!
In other words if I button mash while attacking an enemy (likely to happen when frame rate is this low)the character will continue swinging long after the enemy is dead...stuck there until every last button press that had been que'd up has been satisfied. :(
Is there any way to change this or is it built into flash?
EDIT*
WOW, I just tried in firefox, and two surprises:
1) the frame rate is even slightly worse
2) Despite the frame rate being still worse, it does NOT remember all the button mashing so its much easier and less annoying to play!
Does this mean the button que'ing thing is built into internet explorer and we cant do anything about it?
thanks again
Re: Tips for optimizing for Flash Export
The biggest optimization is probably to update to the latest flash player ...
Re: Tips for optimizing for Flash Export
Loops will really slow things down. thats what killed my last game :(. My current project averages 250 objs on screen and sometimes goes upwards of 500 objs with very little frame rate issues. It could be a certain way you are storing values or an event with no limitations. If your game isn't a super secret I wouldn't mind looking thru your code and potentially solving your problem. but no worries if you need to keep it under you hat. good luck!
Re: Tips for optimizing for Flash Export
I would also like advice on how to optimise the file size, rather than performance. PNG graphics have really bloated the size of my program so far, not to mention having a couple of MP3s. MP3 is encoded at 128kbps, personally I wouldn't want to lower this.
I guess the PNGs are what's really bloating the SWF, but many images I created in Photoshop and as such have alpha channels. Plus, using a soft brush in Photoshop creates anti-aliasing that will look bad if I convert to GIF. Hmmmm. Unless anyone knows how to reduce PNG size I suppose my only option is to do what it takes to convert those that are okay without alpha channels to GIF...
Re: Tips for optimizing for Flash Export
Fastloops tend to reduce the FPS in Flash apps too.
Re: Tips for optimizing for Flash Export
Thanks much for the replies everyone. For those interrested, I've made some descoveries.
1) the biggest hit on my FPS was a really stupid fastloop thing I was doing.
2) After eliminating my own big stupid problem with my fastloop "code" (causing hundreds of loops per frame needlessly) I was able to continue to make optimizations to events and now run my game at a solid 14 FPS while keeping all three scrolling layers!
3) One of the biggest hits to the FPS in Flash exports seems to be math! Every time I removed an event that made one or more object move in a sinewave or that for some reason used fairly long equations I'd get an entire FPS back!
4) It seems like keeping math and fastloops as low as possible, followed by number of active objects, you can keep your game running pretty darn well.
I'm quite pleased so far and have lots more optimizing to go.
Re: Tips for optimizing for Flash Export
Did sinewave use the Square Root function? Apparently that can hit performance pretty hard, depending on who you ask of course.
Active objects is usually the biggest hit I find. 0-100 objects without any kind of assigned movements or events in the editor is fine, 100-200 objects is playable, 200+ and you're eating into your frames-per-second
Most likely a restriction of Flash itself rather than MMF2, unless a Flash CS5 developer can tell me that it handles 300+ objects fine. I wouldn't really know.
Re: Tips for optimizing for Flash Export
I think it did indeed use Square root..that or sine ;) maybe both...I dont remember... but yeah.. the number of actives and complicated math seem to be the two biggest factors...so try to optimize them away before removing scrolling layers. (if scrolling layers are important to you as they are to me. ;) )
Re: Tips for optimizing for Flash Export
You can do scrolling layers without actually using the MMF2 layers. Keep everything in 1 frame and have your layer backgrounds as active objects. Nothing wrong with having a huge 800x600 active, it's much better than a new layer.
Then just make an event like:
Is global value OrderLayers set to 1
- Bring Object X to front, Bring Object Y to Front, Bring Object Z
- Set OrderLayers to 0
So bring every active object to the front in the order that you need them, starting with backgrounds (aka large active objects), then moving to your playable character and enemies.
Then, whenever an object is created a X Y that will mess up the order of the layers, just set your global value OrderLayers to 1, and let your event do all the re-ordering.
That always buys me some extra frames per second.
Re: Tips for optimizing for Flash Export
Quote:
Originally Posted by Ryan
You can do scrolling layers without actually using the MMF2 layers.
I also do it this way. Just keep in mind that MMF has some kind of sync bug which sometimes leads to gaps between the scrolling AOs. Their design should allow to overlap some pixels to avoid graphical glitches.
Re: Tips for optimizing for Flash Export
I haven't had a problem keeping backgrounds in sync, just ensure your background offsets are all tied to a root global value, (ie. don't do X position +1, do X Origin + Global Offset) and make sure they all update within the same cycle, check your offsets to make sure you're not leaving gaps.
Re: Tips for optimizing for Flash Export
I have a 640x480 AO with some simple code:
XPos (AO) <= X Left Frame-Frame Width
---> Create new AO at 1280,0
I already reduced it to 2 lines of code to be on the save side, find an example in this topic .
I used Ball Movement and also tried to move it's X-pos manually. It's not Flash-related, though the effect may be a little worse in SWFs.
Can you tell me what you would change? Always count down a Global Value from 640 and set the AOs X-pos related to it? Where would be the difference?
The fixed X-position 1280 seems to be correct for new AOs, but after a while the error shows. Not always, of course!
Re: Tips for optimizing for Flash Export
At Ryan:
Wow, big actives for layers really is better on FPS in flash than using background objects in actual layers?!? I wasn't expecting that... In my experience its the opposite for Jave for mobile export. I'll have to give that a shot! :)