Jul 012012
 

I’m using the Flex 4.6 SDK and compiling .SWF files with it. Occasionally, I add an SWC library to my projects, and usually they behave normally – whether they are external libraries or internal libraries (In FlashDevelop, right click the SWC file, hit options, and you’ll see the choices there).

Recently, I’ve been using a lot of products from MilkManGames to help my AS3 applications take full advantage of mobile features. As I became more and more reliant on them, I realized I had – at some point – crossed a line where my applications would start crashing on launch on mobile devices… But only when compiled to native bytecode (as opposed to content projector, aka the “fast compile”).

I’ve actually been banging my head against this one for 4 or 5 months. It’s kind of a problem, because content projectors run more slowly than native bytecode. And, more seriously, it’s against Apples TOS to submit content-projector items to the App Store.

In a fit of frustration, I submitted the latest version of IceBurgers to the iOS market as a content projector and Apple didn’t notice, so that’s why you can buy it today. It’s still against the TOS and they could technically pull it at any time, so I still wanted to get to the bottom of this. The fellows at MilkManGames were quite patient and tried all sorts of things. FlashDevelop support couldn’t help. Twitter was no use.

Well, last night, I finally figured it out.

It’s a pretty serious bug in the Flex compiler (and/or a really shitty intended feature?), that only kicks in when your project uses a PRELOADER. Here’s a screenshot of my Main.as file:

You can see I’m using the compiler-command factoryclass method to import a preloader at runtime. I also picked a random .SWC file to include, in this case it is the SilentSwitch utility. I’ve instructed the compiler to include SilentSwitch as an external library – that is, I intend to bundle the ANE file together with it at some point, and I don’t want it to import the library into my compiled .SWF file.

This works as intended, so far.

But if, in the preloader file, I make a reference to SilentSwitch… It will include the SWC library into the SWF file. If I were then to compile it together with the ANE file and make a native IPA file for iOS release, the incorporated ANE classes conflict with the precompiled SWC classes (they are one and the same) and the app will CTD. (haha, that was a lot of acronyms!)

If you’re having trouble following, and have a copy of FlashDevelop, just check out this project I put together. If you don’t have FD or the appropriate compilers handy, I included two SWF files in that archive – one compiled each way, so you can explore and see that the assets were included in one and not the other.

I’m guessing that when the Flex compiler encounters a FactoryClass method, it forgets the compiler instructions for including things externally for some reason.

I’ve filed an official bug report, but in the meantime there is a quick and easy solution: Move all of your SWC references out of any factoryClasses (preloaders) you may have.

Edit: It appears this is a terrible tech limitation of the Flex compiler, and is pretty-much working “as intended.” You are expected to put all external libraries in frame 2… Of course this behaviour is not documented anywhere, and no tutorial mentions it as a gotcha. :)

Jun 022012
 

What makes a really good color theme for your code? I don’t even know. I’m blindly following other people’s examples and trying to find something that works for me. Sometimes I’ll stumble across awesome text editors that have great default themes, and sometimes I’ll bump into threads on forums that have a bunch of screenshots.

I tried to write out what I’d like in list form, and this is what I came up with:

  • I’d like a dark theme, as I do a lot of late-night coding. White backdrops just hurt the eyes with brightness!
  • I know that a flat-black backdrop makes for some quick eyestrain.
  • I don’t like it when a particular element really grabs my attention; if boolean values are bright orange, I get angry!
  • I personally like earth-tones; browns and greens.
  • I also like the old flourescent-green monitors of yester-year and also The Matrix.
  • I want the main body of text – the things I’ll be looking at the most – to be easily readable.

After searching for a while I decided I’d build my own theme. I had seemed to find those elements separately in other themes, but never together in one package.

Here’s what I came up with:

This is actually my third attempt at making a theme and I think it’s the best one yet… But it’s always evolving. I’d be interested to hear what other people look for in a theme (and any comments on this one in particular)! Maybe someday I’ll come across something I can consider perfect.

I used to have a thing for making my comments bright yellow, but I’m veering away from that for the first time as a test. :)

Download here! If you have FlashDevelop installed, just double click the file and re-start the application. I’ve only coded the AS3 language extension, so if you use Haxe or something you won’t get this effect.

Mar 122012
 

“Andy, Andy,” a man shouts excitedly. “I love your blog post on improving mobile performance with AS3!”

Andy has heard this phrase dozens of times now, having just attended a GDC full of flash and mobile development friends. “Thank you, fine sir. I hope it worked out well for you.”

“Well…” He stammers for a few seconds, and tugs on his collar in an absent-minded fashion. “I’m not seeing the performance increase of astounding amounts. It might be a little faster… I just can’t figure it out. It’s a simple game, and it gets quite low FPS!”

Andy has heard this complaint before, and is immediately skeptical, but maintains his composure. He asks the standard battery of questions – did they do the bitmap caching properly, do they have a proper static variable in the wrapper class, but they never seem to lead to a solution. Everything seems fine. That is, until Andy asks the fateful question: “Are you displaying the Bitmaps wrapped in a Sprite, as I suggested in the article?”

“Oh, I don’t need to,” he responds. “I’m using flixel.”

It really is a sight to see; watching somebody calmly grab the edge of a table, and in one quick motion flipping it over. The world seems to enter bullet-time; the salt shaker spinning through the air, the table completing two full rotations before first touching down on the ground. As Andy rises from his chair – face bright red in anger, veins bulging from his incredibly muscular neck – he looks to the sky. With arms outstretched, a primal roar escapes his lips.

Andy then sits back down, corrects his table, and instructs this fellow developer to read the whole article, particularly the bit at the end that says that blitting (and by extension, all blitting engines, such as Flixel and Flashpunk) circumvent the performance enhancements. Andy then recovers the salt shaker, and calmly explains how the start of the article also mentions the use of flash’s standard display list.

The man finally realizes his folly. Flash does not* have access to the powerful GPU on desktop computers, and blitting is a way to more efficiently use the CPU to render things. On mobile devices, flash DOES have access to the GPU, and automatically does a blitting-equivalent of the display list. Telling flash to use blitting manually (by using Flixel/Flashpunk) is telling it to NOT use the GPU, but the CPU instead, hobbling perfromance. He then gives Andy a million dollars.

*stage3d not counted

Feb 292012
 

In June of 2011 I launched a game called ATC Blitz. I had this article half written in my drafts folder, and decided to finally push it out there – now that we have some data!

Inception

After a long day of coding UI stuff for SteamBirds, I settled into bed and had a quick game of Flight Control HD with my girlfriend. With Air Traffic Control on my mind as I tried to fall asleep, my thoughts wandered back to some old ATC games I used to play.

One of my favorites was ATC Simulator by Russel B. Davis/AeroStudios. This is a very high quality product and one of the first indie games I bought – it is as close as you can get to the real thing, even including full-on voice support and using actual airplane data.

Couldn’t the realism of ATC Simulator be combined with Flight Control?

I couldn’t sleep for an hour or two. I lay there wondering if I should just bolt out of bed and get my ideas down – but decided I’d just keep laying there, thinking about the ton of gameplay possbilities here. I was really excited.

Gameplay

The idea I settled on was something like a semi-realistic ATC game. Unlike Flight Control, where airplanes turn on a dime, planes would slowly turn to take on the headings you grant them. You’d also tell the aircraft at what speed to fly, and at what altitude (at least, initially). This would be done from a  familiar interface though; here’s what it ended up looking like:

I actually ended up going for a visual style I first used with Dan Cook in the original SteamBirds prototypes: cut-out airplanes, shadows, and cartoon-like forests. I really like it!

Execution

I really wanted to get this prototype done and out the door as fast as possible, so I set a goal: complete the game with only 24 hours of total work. For the entire game, not just my portion of the work! It’s like a game jam, but with each person you team up with, your time halves!

So right after waking up I started coding and went straight for around 9 hours. Since this game is mostly about time management with time-sensitive movement, this is the first game I’ve ever made that uses the clock as a gameloop instead of just using “ticks” or logic-loops tied to FPS.

The game actually runs at 60FPS, but the planes only update their positions at 10FPS.  That’s allright, since the planes don’t do a lot of zipping around and it makes the UI feel super responsive. It also helps cut down on the expensive collision/landing checking.

It’s always fun to try something new, and I think this approach was interesting – where items in the game are all synchronizing and updating at different speeds. I spent more time than I’d have liked to on it, but worth it in the end.

After I finished up the bulk of the code and the game was playable, I started asking around on chat rooms to see if there’s any artists that want to clean things up for me. It’s hard to find someone willing to get the job done in around 8 hours or less, but Andrew Sandifer was willing to accept the challenge!

We also got together with DVG Music, who was able to put together an audio track for us within our rediculous time constraints. One of my favorite things about the game is the music!

The Twist Ending

After everything was said and done, I sat back and gazed fondly upon my creation. A good little flash game! It was fun, if rough in places. But I hadn’t quite used up my entire 24 hour allotment. What should I do next?

Port it to Blackberry Playbook, obviously! Other than some initial hurdles and signing problems, it ended up being relatively painless with only minor code updates.

Blackberry ended up sending me a free playbook for the deal, and the game remains otherwise unreleased to this day.

Afterthoughts

Two lessons learned with this game.

The first lesson was about user experience and the concept of fun.

Being a pilot, and having played a lot of ATC games, I know about procedures – I know how things should look – I know how fast things play out. Here’s a quick fact: All airplanes try to turn 360 degrees in 2 minutes. Sure, each airplane can turn faster than that, but for the sake of ATC sanity there is a “standard” turn that is both safe, relatively fast, and an important bonus: is comfortable for passengers.

The 2 minute turn is a concept that has been in this game for ages – since the very first lines of code.

And it was terrible. It was not fun at all. I hate it when this happens – I mean, there’s realism, and there’s sticking to your artistic guns… But when it doesn’t pan out? That’s really rough.

The second lesson is about the wonderful world of Twips.

This one was a mind-boggling bug, but eventually tracked it down thanks to the FGL Forums and Twitter. As the aircraft slowly creeped across the screen in full-realism mode, I was incrementing the pixel location values by small amounts (this.x += 0.04;, for example). These changes appeared to be rounded-down to zero and the planes weren’t moving at all.

Turns out Flash stores coordinates in Twips, which is 1/20th of a pixel. That means anything smaller than 0.05 gets lost in the background noise. I was surprised I had never run into this before, but there we have it!

The quick and easy solution is to record the actual X/Y coordinates in your own number variables and increment *those*. They don’t get rounded down. Then you can just say this.x = myXVar;

Show Me The Money!

lol, what money?

I mean it’s nice seeing the occasional cheque every month, but so far the game has only grossed $220. That’s $9/hour! Yesss, above minimum wage! As sales continue into the future it’ll only get better, too!

Part of this is a function of the day-long dev cycle on this game, and how unpolished it really is. The bigger function is this is on the Blackberry Playbook. Frankly I’m happy with how well it’s done!

Future Prospects

Both Andrew Sandifer and I think this game has a lot of potential and – given some actual work and polish – this game could become something awesome. Look forward to a properly-done sequel!

Was it worth it?

I launched a prototype. I got some good feedback on the fun-levels; I learned something new; I implemented new code systems, ported to a mobile device, and dipped my toe in the pond of a new piece of hardware. I’ve got a ton of tested ideas for what is fun in gameplay, and I have a few dozen ideas for sequels.

All of this only cost me around 11 hours of my time. And for my trouble, I was given a free playbook and $220 (which I shared with my co-conspirators).

Worth it? Hell yes.

May 242011
 

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.)

Mar 182011
 

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

Mar 132011
 

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).

Dec 102010
 

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).

Nov 232010
 

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.

Sep 112010
 

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.