Jump to content
  • Advertisement
Sign in to follow this  

Limitations of Flash, optimizing the game and to prevent stuttering

This topic is 2157 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

Me and a friend of mine are making a 2D point & click adventure game together. It's on AS3 Flash (Adobe AIR). It's been a while and we made a good progression so far. Nearly finished the first room with lots of interactable items in it. It will be a grand single player game, so there will be GB's of data. My artist friend is making the graphics on Photoshop and animations on After Effects. Which means they are pixel based, not vectoral. Then he gave me images exported as JPG's and animations exported as SWF or XFL files (as SWF files dumps tons of BMP's into library to work, XFL seems to be a better option).

Everything was going smooth until today. I expected the EXE size would become a problem as it grows bigger and bigger (I'm learning the "loader" class just yet). But what I didn't expected was the annoying stuttering we experienced today. I added an XFL hologram animation on the stage (It's a 12 secs of looping animation), and on the start of each loop the game stops for half a second. We never experienced such a performance issue before, not even close. It is to be the first object animation in the room (other objects are still until interacted). So, I can't imagine what would happen when I put all the animated stuff in the room. It will be unplayable this way.

So, what I want to ask you guys is, what can I do to optimize this game? I must use external object loading from now on, so how should I manage the data files? Which formats should I use for graphics and animations (note that they're all pixel based)? Above these all, are we flying too high? Isn't it possible to make a good pixel based 2D graphics game with Flash (vectoral gfx sucks)? Any little suggestion is highly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
I recommend you start small and grow slowly.

Flash is the least favorite language I've worked with, and it has been the primary UI tool for several games I've worked on. Flash has notoriously bad performance and is difficult to optimize. Even when doing nothing the idle loops can consume a surprisingly large CPU percentage.

Often you will find that one flash operation is fast while another very similar operation is extremely slow. Sometimes the performance of single operations will change between whatever version the host machine is using for their flash player. Doing something slightly different can cause a huge performance difference.

One example we encountered was masking. It is a great feature and could be used for some easy and great effects, but be very careful with it since it can bring even a fast CPU to a crawl. While a stencil mask is easy enough on a graphics card it is horrible in flash.

It CAN certainly be done, and I've worked with several flash animators who were amazing at making tight code. But it is not an easy road. Look at many of the Flash games on Facebook for examples of games that have done it. A few, like Sims Social, have huge memory footprints; Chrome complains that it takes a few hundred megabytes of memory to run.

Yes it is possible to make a good large-scale 2D graphical game based in Flash. Yes, if you succeed you will spend a lot of time profiling and optimizing to get good performance. Edited by frob

Share this post


Link to post
Share on other sites
Just the same as any platform, there are things to know in order to best optimize a game for said platform. I think frob is overstating by saying notoriously bad performance. You have a platform and it's limitations. There are many games that run perfectly fine and are graphically intensive.

To me, it sounds as if you might be running into an issue with Garbage Collection.

Basically if you are creating and dumping large chunks of memory, that can create that pause you describe. I would suggest that you google "garbage collection as3 flash player" and learn about how that works.


Also, If you are using bitmap based animations, I'd strongly recommend that you use bitmapData and blitting.

You will see a huge performance difference if you do this, especially since you are working with pixel based data.

Hope this information helps, as I think you were most likely seeking information such as this rather than an opinion on a platform.

If you have questions, you can send me a private message. I'll help you out as much as I can with what I have learned in this area. Edited by prototypical

Share this post


Link to post
Share on other sites
Thanks for the answers :)

So, now I minimized the mask usage and optimized the code a bit. It ran fairly smooth at first, but after adding some extra background animations it became worse than before. Even if it's not even close to our final projected work.

I read about the garbage collection a bit. But can't really figure out how to optimize the game according to it. Should I manually call the garbage collector to run? I monitored the memory usage by using "System.totalMemory". It starts at 6mb and slowly counting upwards each second. Is it a bad thing?

Also I looked up to that "blitting" thing. I believe that is the answer to my issues, but unfortunately none of the sprite sheet creating software could compute such a big data (as they're all HD animations, frames are too big to fit into one png file). They simply go nonresponsive. Even it did work, a png file for one simple 10 secs animation would be like 50mb (compared to 2mb flv file). Isn't it much less efficient to load such a data? Can you recommend a proper software to handle this? What point am I missing here?

I'm still such a newbie in this. So a detailed explanation would be great.

Share this post


Link to post
Share on other sites
It's hard to give a detailed answer without more thorough knowledge of what you are doing and how.

It wasn't mentioned that you were using flv files in your original post, and there are all kinds of questions that can be asked in regards to that. Are you streaming those flv ??

A flv requires decoding/computation to play the animation.
My first thought is that you can load the .flv and then convert it to a bitmapdata sequence, which then can be blitted much quicker.

Here is a link that can help you understand this issue and a potential solution :

http://ricardocabello.com/blog/post/504


In terms of management of garbage collection, I can't really say that is a solution for you as I can't determine if it is the cause without knowing quite a bit more about your project.

I also don't know if/how/when you are loading in these animations. I would probably stay away from streaming. But it's possible that if you are loading/removing animations as you go, garbage collection just might be one issue you'd run into. Streaming might also cause a pause depending on other specifics.

I'm sorry that I can't give you more specific answers as without specific knowledge I'm just throwing out information based on theorizing.

These concepts - such as blitting, garbage collection, encoding - are not specific to flash. So just a basic understanding of each can help you out a great deal.

Not sure if you have a utility such as this - http://www.as3gamegears.com/profiling/mrdoob-stats/

It can help you monitor things like memory, framerender time, and fps etc.

With something like this tool, you can determine if garbage collection is the issue if a significant memory drop coincides with a stutter/pause. When you see the memory drop, that is when the garbage collection is occurring. In some cases you might not want to make an object available for garbage collection except in places where you can hide a pause or nothing intensive is going on. You might also want to force garbage collection at certain points. Without knowing the design of your game, it's hard for me to be more specific.


From experience, I can say that the most efficient help you are going to get is someone with experience profiling the situation. If you can do that on your own, then the concepts I have described can help you solve the issues. You can private message me if you need consultation in more detail, but I'd definitely need to see code to pinpoint issues.

Share this post


Link to post
Share on other sites
I wanted to note that if you use the concept of converting .flv to bitmapData frames, you will most definitely need to think about that pre-processing time involved. It's really hard to give you a recommendation as how to best handle that aspect without knowing quite a bit more about the overall design of what you are doing.

Share this post


Link to post
Share on other sites
Hey prototypical, thanks for the great answers!

Well, we tried this FLV to bitmapData conversion. There was actually two looping animations in the background (5 secs of 300x800 and 15 secs of 400x300). First one converted and loaded well, but second one just froze on the first frame. After hours of trial and error, we concluded that the conversion class is somehow limited. And even it's not, it'd use more CPU than before. Because even with the first animation converted, game crawls down to 15fps (unplayable). So, it's clearly not suitable for big and long animations. Direct blitting (from a single png file) is way worse, because it needs huge preloading times and to our calculations the final size of the game would be like 50gb or so (no kidding). We found out that, people generally use blitting for tiny (eg. 20x20) sprites with few frames (I hardly understand why, as with today's computational speed, it's impossible to create a difference). So it's not an option for us. And, it seemed like a dead end.

Anyway, long story short, after some roaming in forums and blog posts, we decided to scale our project down. That was a big decision, but needed to be taken early. The game was 1920x1080, now it is 1280x720. We scaled down all the images and videos. File sizes dropped dramatically. And more importantly, this decision gave us the chance to review whole project, and remake it all from the scratch.

So, we opened a new project file. Now, the library is empty and all the assets are loading externally. It's running perfect right now, but we haven't added the character yet, so we're still cautious. I believe the classes which make the character walk have some garbage collection issues. In the old project, each time we moved the char in room, the memory usage was increasing and was never going down, eventually led to a crash. If that kind of a problem persists again, I'll probably ask for your assistance later. I know it's difficult to diagnose the situation without seeing the code. So, if we stumble upon such a critical issue again, I'd send you the whole project, if you're willing to look of course. It's less messy right now.

Thanks for your answers again. Also, that monitoring class has really come in handy. smile.png

Share this post


Link to post
Share on other sites
Dropping resolution will always make a huge difference.
Take a 256*256 image, it would have 65536 pixels. Take a 128*128 image, it has half the height and width but only 16384 pixels, 1/4 as many.

In your case the drop is about 1/2 which is of course a significant amount.

Share this post


Link to post
Share on other sites
haha, ok stating your resolution truly adds quite a bit more context to the discussion!! haha

I was kind of wondering about the 50MB animations etc, and that now makes alot more sense!

I should note that a game using even 1280x720 is quite large in comparison to most games made with flash.

At that size, blitting has larger potential as an optimization for animations.

The issue of memory always rising was most likely a memory leak of some sort. Garbage collection can only occur if you are actually removing references to objects. Once there is no reference remaining, it's basically fair game for garbage collection.

I didn't test out that code for flv to bitmapdata -- i did notice a bug in it by the way - , it was more the concept of doing so that I was pointing you to.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!