00:00
00:00
WarpZone

Age 44, Male

Joined on 1/26/05

Level:
14
Exp Points:
2,076 / 2,180
Exp Rank:
29,011
Vote Power:
5.62 votes
Rank:
Police Officer
Global Rank:
13,255
Blams:
268
Saves:
454
B/P Bonus:
10%
Whistle:
Bronze
Trophies:
1
Medals:
717

How to Not Fail at Making a Flash Game

Posted by WarpZone - January 23rd, 2014


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.


Comments

Good Flash code is an oxymoron.

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.

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

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?

Working on the sequel now, main loop looks like this https://twitter.com/msghero16/status/426441560570347520

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.

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.

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.

...real gamer.

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.

dat list

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

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!

Thank you very much!
Really good reading.