I run the local Victoria game developers group (LEVEL UP!), but our sister group in Vancouver (FullIndie) was having it’s one-year anniversary last week and I was invited over to give a nice short talk of some sort.

The Trip

I had a blast on the trip. FullIndie had probably over a hundred people show up for the birthday celebration, and we all went roving across three pubs after our talks. It was great to meet so many new people – but the size was a bit overwhelming! I couldn’t even meet everyone if I tried.

I took my FlashGamingSummit talk and slimmed it down to around 14 minutes (originally 60 minutes!). I basically cut out all the “facts” and just left the jokes and the summary “lessons learned” and tried to quickly barge through it all. Because of the size of the meetup, I actually had to give the talk twice to two seperate groups of people! They were both laughing most of the way through though, so I think I did a good job. :) It was a lot of fun for me anyway. A student was there filming one of my talks, maybe it’ll find it’s way online someday?

SteamWorks Brewpub let us into their secret cellar meeting room, which was pretty cool. Had some awesome pints and talked my throat raw. Good times!

The day after the event I hung out with some new friends, played some prototype video games, and even got a few board games in. Wonderful trip.

Since Victoria is on an island, seperated from Vancouver without a bridge – we have to take a 1.5 hour ferry ride between the two places. During the day, the view is beautiful and inspiring, as the ferry weaves between the Gulf Islands. At night, the wind and chill is usually so great that it’s best to huddle inside and do something productive…

I decided to do a GameJam!

The Jam

I was jamming on my own but I invited others along via Twitter. I did a screencap of me working at night spliced with the earlier trip during the day. Check out my rough editing skills here:

(Thanks to DVGMusic once again for his awesome tunes that accompany the video.)

In the end, I made an educational game that attempts to teach people fractions. I didn’t have a lot of time so a lot of elements are missing, and it could definitely use some work – but it might be a neat app to develop further in the future. My girlfriend teaches math, and she approves! Check it out the first prototype here:

AheadFull!

(You’re supposed to be at the speed controls of the ferry, being shouted orders by the Captain.)

 

Getting assets (such as images and sound files) into your AS3 project can be simple, but I ran into a few problems (and nice solutions!) that might help others out too. I thought I’d jot it down into a blog post!

How I used to do it

I use FlashDevelop, and I try to avoid using the Flash IDE for development. I found it incredibly handy, though, that I could copy any asset – even vector art – with a simple drag-and-drop into Flash, and export the whole bundle as an .SWC file.

FlashDevelop is awesome handling SWC files; a simple pair of clicks gives you full access not only to the assets, but any sub-classes and properties the assets may have (as imbued by Flash itself). It’s quite awesome, and it’s how I’ve done everything to-date.

The Problem

There are a few downsides to Flash’s SWC asset library:

  1. Porting to other platforms or languages (that don’t support Flash files) is a pain in the butt; without SWC support you have to re-invent your asset importing routines for each platform.
  2. Even when sticking with Flash, importing assets into Flash that you’ve already separated out into individual files can be annoying and tedious (as opposed to developing all your assets within Flash or Illustrator)
  3. You need to own a copy of the Flash IDE (the Professional version, too, if you want to make commercial projects)

The first item on that list is the one that bugged me the most. No other development environment has a standardized equivalent to the SWC Library; converting your game to any other platform or language suddenly gains an extra hurdle, and requires exporting of assets and all sorts of hoop-jumping.  I know this first hand; there was some problems creating the mobile editions of Steambirds.

When I look at various Flash blitting/game engines, such as Flixel and FlashPunk, and they tend to support sprite sheets, image file imports, and other such “industry standard” ways of doing things. Converting from these engines to – let’s say, iPhone – will be a whole lot easier.

There’s just one little thing standing in the way of me following in their path…

I hate SpriteSheets

SpriteSheets were invented by old console programmers that couldn’t manage their assets with the hardware they had. Instead of making large images, they’d break everything down into sprites – dump them all into a single crammed-in file, and re-construct environments piece-by-piece. This is what gives Super Mario Bros. that square look, and why so many games seemed to be built on a grid.

SpriteSheets nearly require you to make all of your assets the same size, and even if you don’t: Any time you save managing dozens of tiny files will be made up in creating a lookup table (or a map) to your spritesheet.

Alternatives?

Well, the standard way is to “simply” use three lines of code to “Embed” each graphic file – at compile time – to your Flash application. I’d love to do this, but I have over 200 files to import!  That’s a lot of typing!

Some helpful Twitterites suggested I might want to look into streaming the files off of a server – but that brings up bandwidth and offline-compatability concerns (but is otherwise a great idea).

Whatever am I to do?!

@ChevyRay to the Rescue

Chevy, the best thing to happen to GDC 2011, took it upon himself to whip up an AIR application that automatically generates all my Embed tags for me, and stores them into a centralized art asset file!

Download his quick-n-dirty tool here: chevyray.com/stuff/AssetBatcher.zip

It did exactly what I wanted it to, simplified a lot of work, and has made my future projects even more cross-compatible with other platforms (and easily portable to other languages).

Thanks Chevy!! <3

 

In the “by the numbers” post a few days ago, I mentioned SteamBirds: Survival introduced a new black-listing technology. There’s been a lot of interest in what exactly this is, so here we go!

First up, I’ll lay the groundwork so you can understand the reasoning here.

How the Flash Ecosystem Works

There are usually a few different “versions” of popular flash games floating around on the web:

  1. The Sponsored Version (primary).The sponsored version typically has no advertisements on it, and minimizes gameplay intrusions to the customer – the games are monetized via other means (such as pay-to-unlock, microtransactions, or placing ads on the website around the game instead). These versions are almost always branded with the Sponsor’s logos. Sometimes this version will have special/bonus content. (Note that you can “sponsor things yourself” by just posting them on your own website.)This version of the game is typically site-locked, so the .SWF can’t be downloaded and re-deployed elsewhere.
  2. The Scraps (secondary sponsorships).Savvy web portals will attempt to profit from a popular game by paying a premium to remove any branding or advertising that may be present. It is common for the fee paid to well exceed a developer’s expected profit for the site via viral advertisements (see #3), thus making this a win-win situation.This version of the game is typically site-locked, so the .SWF can’t be downloaded and re-deployed elsewhere.
  3. The Viral Version.This version of the game usually has in-game advertisements of some sort, and usually some kind of branding for either the developer or the primary sponsor. The game is then put up in various free locations (such as FlashGameDistribution.com) so that any portal may get the game for free.Because no sponsor is paying for this version, the advertisements provide revenue for the developer.

As a case-in-point, the viral version of SteamBirds exists on around 5,000 different websites, which account for around 30% of the game’s total traffic; that’s where I generate most of my advertising revenue (not that there is a lot…).

Arguably more important than the advertising revenue, though, is the branding. Getting your brand (in my case, a link to steambirds.com) in front of millions of people is potentially more valuable than a few pennies for ad clicks.

Which brings us to the big problem.

Evil Jerkwads

Some enterprising portal owners think to themselves:

  1. I see that game is doing really well;
  2. I want it on my site;
  3. I don’t want the developer’s ads on my game;
  4. I don’t want to lose my customers with outbound links;
  5. And I don’t want to have to pay for the game.

They will then grab the free, viral version of the game – and do some or all of the following evil, jerky stuff to it:

  • Remove the ads completely
  • Change ads or overlay their own ads on top of the developer’s
  • Prevent the game from opening links when clicked
  • Replace the links with links of their own choosing
  • Hack out the site-locked sponsored versions to illicitly grab the unique content
  • Replace any/all branding
  • Entirely eliminate credits screens
  • Put their own names into the credits screens

As Adobe’s Flash/AS3 language is an “open” language, there are plenty of decompilers out there. Asset protection is still difficult in the environment. Doing any/all of the above is a trivial process for most developers.

The original version of SteamBirds had around 4 million plays with various iterations of the above list implemented. Most often it’s ad-replacement and blocking of outbound links; I think only one site erased my name from the credits; other games aren’t so lucky.

Flogging with a Wet Noodle

The offenders here are almost exclusively based out of Asia, and most of my illicit traffic comes primarily from China.

Sending cease-and-desist letters from a lawyer, pleading via email, and making angry blog posts in English doesn’t work. Any attempts I have made have gone completely ignored; at best, sites will write back claiming they are doing you a favour by exposing you to a large Asian audience.

It’s hard to bring litigious action against these portals when the value of the traffic they are stealing is diminishingly small. 4 million hits across hundreds of sites? That’s not many visitors each. And it’s hard to put a value on branding, such as “name in the credits” or “outbound links back to my site.” Not to mention bringing litigation against a Chinese site is very difficult to do, thanks to differing international laws (nor would I want to go down that road).

It’s not that I want to shut a single infringer down, or that any individual company is harming me directly in a measurable way; It’s that there are so many of them. Stopping them one at a time won’t get me anywhere. I need a way to flip their entire table over, all at once.

Prevention is the Best Medicine

Because Flash is an open platform, ripping things off is easy. There are certain things you can do to make the whole process more difficult, though.

Simple changes in the way you code, for example, can result in corrective action. If you play SteamBirds: Survival on a site that blocks outbound links, I can actually detect the failure event in the code, and display a popup box that says “This site is being a jerk! Type this URL into your browser bar…”

Using metrics-recording platforms like Playtomic will allow you to track the number of advertising clicks on each site. If there is a lot of traffic with zero clicks, you can take dynamic (code-based-blocking) or manual (off-site blacklisting) corrective action.

And finally, you can use code-obfuscators to help prevent cracking/hacking of various kinds. These automated programs run through your code and change function names to things like ” ” or linebreak characters, amongst other things. I use Kindisoft’s SecureSWF Pro on most of my projects, and I believe it is the best in the industry.

No matter how much prevention you use, you can’t prevent all types of hacking though. With work, any obfuscated code can be reverse engineered; and there is currently no way to encrypt or obfuscate your art assets. Why hack out advertisements or branding when you can just relocate it to be off-screen, or re-paint it as your own?

Enter the Dynamic BlackList

Since I had a nice, long list of badguys from SteamBirds, I decided to put it to good use in SteamBirds: Survival.

Here’s how it works:

  1. I Include the entire list of the offenders URLs as a single XML variable in my code
  2. I then pull a stored GameVar from Playtomic‘s servers to update the list in my code. This prevents people from decompiling the game and just removing their URL from my internal XML (and is quite probably the biggest headache for would-be crackers, since it isn’t an obvious update).
  3. The game tracks ad clicks and looks for other “red flags,” and notifies me of potential infringers. I can then log in to Playtomic and update the GameVar if I believe the site needs to be added to the list.
  4. Upon execution, the game checks the hosted domain against the list. If the site is blacklisted:
  5. The game displays a nice, friendly, pre-made image saying that the game is – unfortunately – not playable on that site, and redirects the player to SteamBirds.com
  6. In case they hack-out the nice art asset I made for the offending sites, the game constructs a much uglier, nastier-sounding “this site is being a jerk!” message from pure code, using no art assets. This is much harder to hack.

It worked really well. The sites that used to be a big thorn in my side? Now very nearly zero traffic. I successfully put up enough barbed wire to discourage the dismantling of my game.

Right after I launched my game, Playtomic released a similar service that covers a lot of the basics: Portal BlackList. It doesn’t have all the bells and whistles of my system, but it provides all the code and integration you need to get a simple system up and running today. I recommend checking it out.

Portal BlackList also shows a list of currently blocked sites in the sidebar. My list is a subset of those sites, so instead of duplicating it here I’ll just direct you there! You can also check out the list on Free Our Games as a reference.

Still Failing

Unfortunately, there are still ways around all of my safeguards. Certain portals will link to your game on your own website, hosted in an iFrame on their own site. Your game then thinks it’s running on a proper domain, while the offending site can strip out any accompanying sidebar ads, branding, or whatever else you might have in place.

Thankfully the number of people doing this is quite small, and not a big deal (for me, anyway).

 

Crab Attack 3 is one of my 12G Games. Read the intro article on what 12G is all about!

Inception

Crab Attack 3 comes from a rich heritage of pure-blood crab-attacking games. You might recall seeing Crab Attack, my 5-minute-game challenge game… Or you might even remember the good ol’ times with Crab Attack 2, a feature-enhanced version of the original vision.

Crab Attack 3 brings in a whole new re-imagining of the game, with fresh visuals, unique gameplay improvements, and … uh, well, … hmm.

In truth, total development time for Crab Attack and Crab Attack 2 didn’t even top 20 minutes, so I thought it was safe to roll them right into the “trilogy” project as part of my 12G game challenge. I kinda liked where Crab Attack 2 was going, and decided to see if I could turn it into a viable product. The game also presented a bit of a hurdle: it contains a lot of moving on-screen bits, and keeping the framerate low would be a challenge!

Execution

Working from the existing codebase of crab-attack 2, I started adding some placeholder art and immediately noticed the game starting to slow down; my FPS was quartering. The game was also lacking pretty seriously in the “fun factor” department.

I addressed the latter issue by tossing in some fairly random risk/reward items. There are now golden crabs you can pick up (but it is dangerous to do so), the water now slows you down, and you can also get points for jumping on the grass (but golden crabs don’t appear there). Optimal gameplay is now to stay on the left side as much as you can, ducking out to get crabs and slowing things down in the waves, before heading back again.

To address the performance problems, I realized I was encountering problems as discovered in my Flash Performance Testing Posts (one, two, and three). I asked around and ended up finding the excellent Ginger bitmap animation API (It looks like the site is no longer updated and the download link is old – be sure to use the SVN link on the page).

The Ginger API does one thing particularly well – it will accept a multi-frame vectorized MovieClip object, and convert it to a variable-FPS bitmapped animation – complete with pre-rendered rotations. I was so happy to find this. Implementing this immediately brought my FPS back up to the levels of Crab Attack 2, where everything was simple square blocks.

Once the game was nearly complete, I teamed up with Ben Schlessman of Games Northwest (aka ShooterMG) to handle my art needs. He ended up working really fast and providing some neat art in the theme of the game; I say I’m pleased with his performance!

At the end, I slapped in some cheap epic music from DVGMusic. Thanks!

All in all, I put around 10 hours of work into the code. Ben Schlessman put in around 8 hours of work to the art. The rest of the 24 hours was spent on wrangling the game through FGL and Mochi.

The Game Itself

Enough words, let’s see this thing in action! Click here to play.

The Results

Well, the game did the rounds through FlashGameLicense and found no sponsors. Few people showed any interest at all, in fact! I could probably shop the game around to specific mouse-avoider-style sponsors, but I decided to use the game to test out Mochi’s Distribution platform. The game now features pre-roll ads through them, and might make me a few dollars as time goes on.

I’ll make a new post if I suddenly get a boatload of advertising money, but I think this is it. Crab Attack 3 is done!

One thing that I did note: Most people don’t like the game at first glance. It isn’t much of a challenge and it’s not entirely enjoyable. However, once somebody calls out their high score – people tend to get excited and start competing. I think CrabAttack3 is a good “Party Game” but not a good “video game.”

Lesson Learned

The biggest lesson I learned with the Crab Attack trilogy is proper handling and easy conversion of Vector Art to speedyQuick bitmap graphics. The entire game was built to be cluttered and fast to start with – and I know the easy-to-use .cacheAsBitmap flag built right into AS3 – but when things start getting complex, it’s nice to know there’s a pre-written API like Ginger that will quickly and easily convert all my data for me.

Future Prospects

I think I’m pretty much done with Crab Attack. I’ve been itching to make a MouseAvoider-style game for a while (just to say I did it, not for any interesting reason), and this satisfies the urge quite nicely. I can’t see gameplay getting too much more interesting (though it could definitely improve).

 

I just ran into good ol’ Flash Error #2136. Here’s the entirety of the error message you get, not at compile time, but at runtime:

Error #2136: The SWF file contains invalid data.

What data exactly is invalid? LOL, as if!

I tried googling the error, and it gives a whole bunch of advice on how to disable a document class, or how you shouldn’t export SWCs with wacky options, or all sorts of other nonsense that doesn’t apply to me. Most seems to have been written years ago. Which kinda tipped me off…

Here’s what worked for me:

  • Flash: File > New > Flash AS3.0 File
  • Copy the entire “library” from your old FLA
  • Paste the entire “library” to the new FLA
  • DELETE THE OLD FILE, IT IS MAGICAL POISON

That should resolve all your problems. I spent a good 4 hours on it. All the settings between the two files for the same; the only thing different was the original file used to be a CS3 file and the new file is natively CS4.

I hope this helps save someone else some time.

 

I’ve gotten a bit of feedback on my performance posts from a few different sources. Enough to make a new article on the subject! See part 1 here, or jump to part two here.

The Source Code

So people can take a look at how I’m doing things, or what exactly the base code is up to, I’ve packaged up the source code for SolarCraft.  Remember: this was a two-hour hacked-together-from-scratch bunch of code. Don’t judge me too harshly! I think it’s a decent testbed for performance because it has a basic game-style logic loop and a few iterations through large arrays… But most of all, isn’t designed to be “perfect” or “most efficient”; this is to test real-world game-performance, not theoretical performance maximums.

Download the source here.

Rotating bitmaps by 90 degrees

User areagle of the FlashGameLicense forums asks if rotating bitmaps by exactly 90 degrees provides any sort of performance boost, since the math for doing so is much easier and less intensive on the CPU. Decent enough question! Let’s get some baselines first.

1000 collectors on-screen, .cacheAsBitmap true: 48.0 FPS

Adding +.01 rotation per tick: 14.0 FPS

Changing to +90 rotation per tick: 13.2 FPS

Changing to +180 rotation per tick: 14.5 FPS

Changing to +360 rotation per tick: 48.3 FPS

Well, it looks like the rendering engine is smart enough to know that a 360 degree rotation won’t affect speeds, which is nice; now I know that simply setting the .rotation property isn’t enough to cause a performance drop. 180 degree rotations were a smidgen faster than smaller increments, but that may  have been luck; I’m willing to call this one potentially true, but for game development’s sake, doesn’t matter.

Different loop styles

This one was brought up a few times in different places (twitter, forums, blog comments) and I can’t help but think people are missing the point. People are saying I’ll see a significant performance difference between the different loop styles.

Now, I will believe that a while loop might be a bit faster than a for loop. But compared to game logic and rendering times, I’m betting this speed difference is going to be less than a single percentage point. I’ll bet I can’t pickup the difference from the background noise. I believe loop speed differences are only useful to people crunching through massive amounts of data (like, one-million-entity-arrays or something).

Since I have my code open anyway, why not appease the masses?

There are two main game loops, both updated in the Update() function in Map.as (line 68); the first loops through a vector of 1000 collectors, removing any dead entries (there are no ways to die in this version, so no action is taken); the second loops through each collector and runs their respective .update() functions.

Baseline: Using two FOR (var i…) loops, 46.7FPS.

Converting both to be FOR EACH (var entity…) loops, 47 FPS.

Converting both to WHILE loops: 47 FPS.

Without getting too in-depth here I’m thinking my hunch was right: Loops might make a big difference in big data sets, but in games it simply doesn’t matter.

Debug vs. Standalone vs. Browser

Different Flash players get different performance values. I noticed this while performing other tests for this series of articles, and I know there is definite value here.

Using the standalone Flash 10 Debug Viewer – which I do my sole development in – I get 27 FPS with 2000 collector’s on screen. I kind of assume this is the performance that people will get when they play the game on the web; let’s test:

Using the Chrome & Firefox Flash Plugin Viewer, I get nearly 50 FPS in the same environment!

Using the Internet Explorer ActiveX Debug Viewer, I get 19 FPS in the same environment!

Out of curiosity, I downloaded the standalone Flash projector (non-debug) and maxed out at 60 FPS.

So there we have it. All debug viewers are nearly half the speed of their counterparts, and the web plugin is definitely slower than the standalone version of the player. Keep this in mind! If you do all of your development and testing in a browser-based debug viewer, you are essentially simulating a slower computer.

Multi-app same-page performance differences

Back in my last performance post I toyed with how the target FPS might affect performance (it didn’t). A few people said that this actually is a real issue even for us game devs, but the problem only crops up when an .SWF is hosted on an HTML page that has a bunch of other flash things playing — such as the portals we deploy our flash games on.

One side of the argument says that aiming for a higher framerate than what you can achieve, can actually tax the SWF player and produce a lower FPS than intended. Another side of the argument says the SWFs “compete” for slices of the timing pie when several instances are launched, and the more resources you demand – the more resources you get.

Seems like a perfectly reasonable assumption, and is indeed well worth testing out. Let’s give it a go.

For this test I’m going to use a baseline build of 4000 collectors running at a target of 30 FPS (using the non-debug browser player). I’m getting 21 FPS on Kongregate.com (uploading my game but not ‘publishing’ it).

No matter what I set the target FPS to, the value is not wavering, despite there being flash ads and Kongregate’s achievement/chat interface on my screen.

Just out of curiosity, I opened two tabs (one set at 30 FPS and the other at 60 FPS, both hosted on Kongregate) and played each flash game tiled on my screen. Performance still did not waver from a solid 21 FPS for either copy.

Looks like I can’t replicate any web-based test conditions! I’ve now tested this “Target FPS” thing a dozen of ways and can’t seem to make it affect performance at all. I’m thinking that in the majority of cases for actual game development, this will not be a concern: set your FPS to whatever you feel is best and the game will perform as best it can. Why limit things? Set your FPS to 120 for all you care! (Note: Flash Player 10 does indeed limit max frame rate to your screen’s maximum possible refresh rate, so it’s not possible to ‘waste cycles’ doing this)

Off Screen Rendering

A curious thing I noticed in my performance graphs when playing things in tabs: flash skipped rendering cycles if the viewable area of the game was physically not visible on my screen. If my game ran minimized, was in another tab, or was scrolled off the edge of my monitor, my performance maxed out pretty quickly. It looks like Flash only bothers rending when it’s open or active (for the browser plugin, anyway)!

Good to know: Don’t do performance tests if the window isn’t open, front and center!

Conclusions

Throughout all of my testing, I’ve really only concluded one thing: The only place you can possibly optimize your game is in appropriate use of bitmap graphics. Any other “tweaks” you can make either have such little effect as to not be relevant to game developers, or have no effect at all.

 

As I was waiting to be interviewed for FlashGameLicense, I decided to make a game to prove a point: That it’s possible to quickly prototype an idea, just to see if it might have legs.

The people in the FGL chatroom mentioned “Snails with Propellors flying around” and someone mentioned “Cooking” so I decided to merge the two:

You are an intrepid SnailCopter, looking to push the Eggs (green boxes) into the frying pan (red skillet). Avoid the falling Salt!

The game has pretty LOL-tastic physics (I coded them completely from scratch, and I ashamedly had to Google F=ma and v=v+a.. sigh). Using the performance enhancing techniques I learned in the last few articles, I’m getting a solid 60 FPS with all these objects on screen :)

Not bad for an hour! I think this game has promise; might sell for a grand or two on FGL if I polish it up.

 

Following up on my previous article, I wanted to test a few more things. For the sake of generating clear numbers, I’m using yesterday’s 2-hour game SolarCraft as my testbed.

Throughout these tests I’m spawning 2000 collectors with cacheAsBitmap enabled, and running the test for 30 seconds and providing the average FPS (which will therefore include, but hopefully minimize, startup lag throwing the numbers off a bit). As I mentioned in my previous article, I’m trying to get real-world numbers (using believable in-game item counts) with other things going on (such as graphics and game logic loops).

Vector vs. Array

Vectors are new in Flash 10 and are, put simply, a typed array. Many claims have been made on the huge speed increases when using Vectors (I’ve heard 250%+); let’s test it out!

A 2000-length vector iterating twice per frame generates me an average of 26.5FPS.

Converting the code to untyped Arrays provides me an average of 26.0FPS.

That difference can easily be chalked up to various other things and is pretty much indistinguishable. It looks like, for the purposes of this game, Vector iteration isn’t much faster at all.

However, I still love vectors for being typed. Still worth using, no harm in it and your code will be easier to work with!

Loop Iterations

“Hey wait,” I hear you saying. “Why do you loop through the 2000-length vector twice per frame?

Good question! It was because I made sloppy code and thought it would be a good idea to simply loop through everything again rather than fix it (that’s how you make 2 hour games!).

For clarity, one loop is simply cycling through all game objects (in this case, 2000 collectors) and running their “update” function. This function calculates where the collector wants to go, runs a few randomization jitters, and does some simple coordinate translations to produce a vector. Then they “walk.” Nothing exciting, no big maths.

The other loop is just checking for dead collectors and culling them from the Vector (not that anything is dying in these tests).

As a baseline, we are currently getting 26.5 FPS.

So I’m curious.. let’s comment out the useless dead-check loops and see what kind of performance boost we get. Looks like 27.2 FPS. A slight increase, maybe even one worth sticking with; a single frame per second optimization in a few places might add up.

Let’s remove the walk-logic loop and see how that fares. Looks like 29 FPS. This one was to be expected; removing all the art movement and gamelogic from the game should very well speed things up. To be fair, the “current FPS” was locked at 30 for a long time, and we only got 29 FPS because of my 30-second-average including bootup delays.

Well, let’s play with this dead-check loop again. What happens if I make it run 10 times, thus iterating the game through 22,000 vector entries per frame? We get a result of 22 FPS. That’s a significant hit for a loop that doesn’t even do anything.

I think it’s safe to conclude that iteration through long lists – regardless of content or actions – is a big performance hit. But putting in a useless duplicate iteration 10x over? Not exactly a “big problem” in game design, I think. You’re better off ignoring this issue and optimizing what happens in the loop itself.

Playing with Target FPS

If you tell Flash to run 30 frames per second, it might run at 25 FPS thanks to your inefficient code. I’ve heard, however, that if you tell Flash to run 60 times per second with the same code – that 25 FPS might drop to 10FPS. Trying to over-achieve can actually hurt you!

I’m really interested to see if this holds true in my game.

I’m currently running at about 27FPS, on average, with a target framerate of 30.

Changing the target framerate to 60…  Has little effect! I’m averaging only 1 less: 26FPS.

Let’s crank the target framerate up to 120… Hmm. My monitor refresh is 60hz, I wonder if Flash can sense that and scale down my request? I’m showing a target of 60 still, and still hitting 26FPS. Oh well.

Just for kicks let’s drop the framerate down to 10 an see what happens: Wew, a solid 10 FPS. At least I know there wasn’t some weird overhead preventing me from hitting 30FPS before; it looks like my code really is a bit too slow (or I have too many dudes on the screen).

 

I’ve done a lot of reading on performance enhancements and testing solutions for Flash, but I’ve never actually done any A/B testing of my own. Let’s fix that.

I’m using yesterday’s SolarCraft as a template; it has a few game logic loops and a bunch of movement on the screen, vector calculations and Vector iterations. I think it’s a good “realistic” platform, as opposed to looping through display-less routines or something. I hope to gain practical data here, not theoretical!

For each of my tests I simply adjust the number of  ”collectors” that spawn when you click on the base in SolarCraft. This gives me a quick and easy item count, and I’ve tacked on a profiler to see my memory use and framerate.

cacheAsBitmap

Setting the “.cacheAsBitmap” property to “true” on DisplayObjects is supposed to make normally-vector art display faster, but only if the art translates (not if it rotates or scales). Let’s see!

With cacheAsBitmap set to FALSE, I can maintain a constant 30FPS with a maximum of 800 collectors on screen. Memory use peaks at about 8.25mb. Or roughly 0.010mb per collector.

With cacheAsBitmap set to TRUE, I can maintain a constant 30 FPS with a maximum of 1,900 collectors on screen. Memory use peaks at about 26mb, or 0.013mb per collector.

A slight (but marginal) increase in memory usage for more than double the performance! That’s pretty good.

Adding Rotation

As it stands, the collectors are only translating; let’s see what happens if we add a slow rotation to the collectors each frame ( collector.rotation += 0.01 ):

Eek. Using the previous 1,900 collectors,  my performs drops from 30FPS down to 8FPS. Attempting to regain my 30FPS, I had to drop my collector count to 500 – below our baseline 800 figure when cacheAsBitmap is turned off.

With cacheAsBitmap turned off and rotations left on, I easily reach back up to the 800 mark at 30 FPS.

Seems like vectors are indeed much better performers when it comes to rotation (and memory usage didn’t change).

Scaling

I’m replacing my rotation code with scaling code ( collector.scaleX += 0.01 ) to see if we get similar performance numbers as we did with rotations.

With cacheAsBitmap turned off, I hit 30 FPS with 700 collectors on screen. a Slight performance drop from our Scaling experiment.

With cacheAsBitmap turned on, I hit 30 FPS with 500 collectors on screen.

So it looks like cacheAsBitmap performs equally as poorly with scaling as it does with rotation; but default vector behaviour handles rotation better than scaling.

Rotation AND Scaling

The results of this test were identical to the Scaling test, so I won’t reproduce them here.

Conclusions

It looks like Adobe’s documentation was factually accurate. cacheAsBitmap gives you significant performance gains if you don’t rotate or scale your vector art at all, and stick to simple x/y translations. cacheAsBitmap will also marginally increase your memory footprint.

But those results I expected.

What I didn’t expect to see was scaling performing worse than rotation in the vector realm. That’s interesting…

 

I was challenged to make a game in 2 hours. I find it hard to turn down challenges. :)

Introducing: SolarCraft

This is a semi-automatic RTS; you start with $1000 and can buy Collectors by clicking on your red base. They will head out to collect resources; if they return to your base you earn $10.

You can also place towers for $100, which will shoot and kill your collectors as well as any badguys. Click on the tower to tear it down for $20.

Badguys will suicide bomb you. If you lose your base, you lose! (Game will auto-reset)

Built this from scratch in 2 hours; no development tools, graphics, or code libraries other than what is included with FlashDevelop and the Flex stand-alone MXMLC Compiler. Took me exactly 101 compile attempts. :)

© 2012 Andy Moore Suffusion theme by Sayontan Sinha