Contact Info / Websites

Entry #22

How to Not Fail at Making a Flash Game

2014-01-23 18:00:17 by WarpZone

How not to fail at making Flash games

Every now and then I see another game that makes me want to shake the developer and scream.  I'm sick and tired of people posting these games with highly-polished graphics and gameplay that just break and fall apart the moment you play them for more than five minutes in a sitting.  Sometimes I'll rant about programming best-practices in the review itself, give the programmers some terms to Google, but by then it's always too late.  Everyone knew this shit back in 2004.  What happened?  These bugs are inherent to Flash itself.  If you don't know how to work around them by now, you need to educate yourself.

So here.  Here's an image showing exactly what happens when you develop something the quick-and-easy way in Flash and then just trust Flash not to fuck it up when the game's been running for a while.  Also, a general overview of how to fix.  These are the mistakes I keep seeing so-called professionals make over and over again here on Newgrounds.  They make your game break, slow down, freeze or just plain start behaving strangely beyond some point.  They are show-stoppers.  They are mission-critical points-of-failure.  You will not anticipate them, because they are caused by weird shit internal to Flash.  You can only stress-test for them, or engineer around them by coding things the hard way.

To learn how to fix, Google all of the following search terms and read, read, read:

  • AS3 bitmap display programming
  • AS3 delta timing
  • AS3 object pooling
  • AS3 performance optimization
  • AS3 garbage collection problems

Good luck.


You must be logged in to comment on this post.


2014-01-23 19:34:35

Good Flash code is an oxymoron.

WarpZone responds:

Did I say this would make your code good?

I'll be happy if you write ugly code that doesn't break the 500th time an enemy fires a shot.


2014-01-23 20:58:10

You can force garbage collection if you know you'll have some time where frame skipping doesn't matter (end of a level, menu, etc) with flash.system.pauseForGCIfCollectionImminent(). I've never had a problem with it though.

Good tips, especially copyPx

(Updated ) WarpZone responds:

Sometimes, "I've never had a problem" is the problem.

Having said that, I've seen your games, and performance-wise, they seem pretty solid.

If you don't mind my asking, what's the main loop look like in Juggernaut?


2014-01-24 09:29:39

Working on the sequel now, main loop looks like this

Consists of:
Update current state (some states have collisions and movement, some just animations, some nothing)
Render current state, I use a mix of sprites and copyPx that suits performance and clickability.

Only when entering a new city does the performance ever rise, and only for a single frame.


2014-01-24 10:08:18

You mean that if you use Movie Clips and don't take into accout the framerate lag, then game objects will get stuck in walls? That's clearly not the reason for bugs. Maybe performance - yes. But not bugs.

WarpZone responds:

Okay, I didn't spell it out in the image, but what I think is going on here is that it's using addChildAt to layer all the bullets and enemies and things as MovieClips on the stage. If you code this in a slackish manner and don't test it by running the game for as long as an actual player would run the game, you won't realize that at some point that int you keep incrementing either wraps or hits the built-in child limit and defaults to something else. Now your code is trying to update bullets that don't exist, and the bullets that do exist just appear in mid-air and don't move.

So, yes. If they used BitmapDatas instead, they could have avoided this.

They could also have avoided it by keeping track of their child layers and being wary of the limitations and testing it thoroughly and finding a graceful way of establishing a practical ceiling on child layers and handling it nicely when that ceiling is reached... but essentially you get all that and more if you just implement Object Pooling.


2014-01-24 18:07:10

...real gamer.

WarpZone responds:

Yeah, you know. A real flesh-and-blood human being who is playing your game. I.E. not playing like a developer running a test case on a single feature.

An end-user. A player. A consumer. An operator. Take your pick.


2014-01-24 22:25:36

dat list


2014-01-24 23:09:36

Damn, I wish I knew what you were talking about, or even how to apply it.

WarpZone responds:

Google is the genie that can make your wish come true!

Perform the following Google searches and read as much as you can:

AS3 bitmap display programming
AS3 delta timing
AS3 object pooling
AS3 performance optimization
AS3 garbage collection problems

Good luck!


2014-01-26 21:25:48

Thank you very much!
Really good reading.