Essential Flash Games Book Chapter 12: A Viral Game In A Day
I know a lot of people do it, but I have never really been a "game in a day"
kind of guy. With my day job, kids to play with, books to write, games to
review, etc, I usually don't have the time to devote enough hours in a single
day to make a 24 hour game...until yesterday. Actually it was a 24 hour span
from Tuesday Noon until Wednesday Noon. I needed a game for the final chapter of
the Essential Flash Games book, but it couldn't be too complicated. The final
chapter is on viral games. It begins by discussing how to take all of the code
created in the first 11 chapters and organize it into a re-usable framework and
package structure. Next it takes the structure and creates a simple game using
it. Finally, we add in both a Flex SDK pre-loader and an Flash IDE pre-loader,
as well as Mochi ads and leader boards. On Monday, everything was complete
but the game, and I was under the gun to get something new coded FAST. Since the
chapter is on viral games, and most likely those games are completed at a very
rapid pace (a couple days maybe), my production time and schedule would simply
mirror the production time that a viral game developer might employ. This would
also give me an interesting angle for the chapter copy.
[Tunnel Panic In Action]
I chose a 24 hour period so I could authentically write about how to create a
small, quick viral game. The game I created will not win any awards for
originality. It is called "Tunnel Panic". The Tunnel Panic portion of the
chapter is going to be written in more of a narrative, story-style form that
describes what a 24 hour game development cycle is like and how using a
pre-existing framework, package, and template structure can aid in rapid game
development. The game is one of those "fly through a tunnel and dodge
everything" type of games. Your ship is always moving forward and gravity is
always pulling it down toward the bottom of the screen. The player only needs to
press the space-bar to thrust up. There are no other controls. The game lasts
for roughly 60 seconds, but it will not be going into the Mochi 60 second game
competition because it doesn't have any chance of winning.
To finish in 24 hours (only about 8 of them were spent on the actual game), I
had to limit the game-play and cut a lot of corners. I am no artist anyway, but
the graphics in Tunnel Panic are even simpler than my normal routine 8-bit fare.
The scrolling is created by simply moving a pool of obstacles from right to
left at a rapid pace. The player's ship is a vector shape drawn into a simple
Sprite that stays in the middle of the screen (horizontally) all of the time (moving up and
down). The obstacles are simple Sprites with a single pixel BitmapData object
inside each. The Bitmap holder for the BitmapData object is scaled to the width and height
needed for the object and setPixel32 is used to change the color as
needed - the obstacle colors change as the game gets progressively more difficult. This gives is a little bit of and Atari 2600 feel.
The exhaust for the ship is created as pool of particles that blit to a
separate canvas (used solely for them). They blit from an array of alpha faded
BitmapData objects that is pre-created at the init time for the game. The
collision detection is simple "hitTestObject" (and it shows). I did this because
the scaling of the Bitmapdata inside the obstacles made Bitmapdata.hitTest
impossible. The music and single sound effect (there is only one) were pulled from the pre-existing
library of music and sounds that we have created over years.
The Flex SDK pre-loader was a stretch. It uses the Flash Develop model which
works great, but requires a compiler directive to fake the Main class starting
in frame 2. It's quite a little trick that I didn't know about until a couple
days ago. The Flash IDE pre-loader is a three frame model with the library assets
not exported in the first frame, and an asset holder on frame 2. The Main class
pre-loads the movie on frame 1, then plays the play-head passed frame 2 (the
assets from the library are there) and stops on frame 3. In this IDE version, the
pre-loader is a STATE that can occur after the Mochi ad, but before the
title screen STATE. It is needed even if the Mochi ad preloader is turned on because it acts as the actual asset library instantiator and not just as a pre-loader. This is not needed in the Flex SDK version so the pre-loader process is optional if Mochi ads are turned on in that version.
The flex version requires the preloader class to take place
of the "document" class that was originally the "Main" class. This model requires
Main to no longer be the "always compile" class, but instead be added to the
display list of the Preloader shell class at run time in a "fake" frame 2. In
any case, each version still produces a single game output swf file. Aside from
handling assets embedded at compile-time, this was one of the few real
differences I found throughout the entire 12 chapters where the IDE and Flex SDK
are concerned. The code and structure of the pre-loader needed to be completely
different to support the two different application development models.
So, chapter 12 will be complete in a few days, and then it is back to the
re-writes and "what the hell were we thinking" changes that go into re-reading
something from 6 months ago. I already found a problem with the Pause function
created in chapter 11 and have to re-write that one ASAP.
Essential Flash Games Book, Chapter 11 - An Optimized Scrolling Blaster
Chapter 11 is by far the longest chapter in the book so far and will probably remain so. There is only one more chapter and Steve and I want to keep that one under 40 pages. It was due yesterday and took much longer than I thought it would to write this one up. I spent about a week making the game, Blaster Mines, a Geometry Wars style blasting contest. I decided to use the mouse for control and in the middle of development downloaded the latest Flash 10 players for XP and Windows 7. To my horror, the mouse would not work while the game played at a high frame rate (it had worked fine on all of the previous player versions on all systems). This had to do with a bug in the Flash player when updateAfterEvent is turned on while using the Sleep-based Active Render Timer. The timer skips rendering on frames to keep a constant frame rate, but on older systems it seems to also omit some mouse movement detection. The first thing I did was remove the updateAfterEvent from the timer, which worked fine, but the game looked a little choppy at high frame rates. The problem was solved by lowering the frame rate to 30. At that frame rate, the updateAfterEvent would work also.
Blaster Mines In Action
I wasn't satisfied though, so I added a render profiler to what I call the AdvancedTimer class. This timer profiles the player's system before the game runs and picks a suitable frame rate that will hopefully run the game with mouse control intact. I did this because I wanted the game to be able to take advantage of newer systems that can sustain higher frame rates, and also very old systems that cannot. This set me back about a week as I played with multiple different timers and profilers, but was never satisfied with any game timer other than the Sleep-based Active Render Timer.
The book covers this subject by offering 2 alternative timers (neither quite as speedy), and also the profiler and AdvancedTimer. The best bet for all games that use the mouse and require a lot of moving objects is to lower the frame rate (to about 30) and turn off the updateAfterEvent. But, if you like to push the envelope, the profiler will help you do so. The profiler uses a new FrameTimer class that also displays the current memory pages in use (a little like a baby version of ActiveGraph). This allows the game developer to see if all of the garbage collection is happening properly and to test for more than just the standard Flash player memory leaks. When combined with the AdvancedTimer, the FrameTimer will also display the current frame rate relative to the maximum profiled frame rate. This is key to testing whether render hiccups are caused by giant pages of memory being re-collected.
The game is a pretty standard Geometry Wars / Asteroids scrolling blaster. The game world is set on an 800x800 BitmapData canvas. A scrollRect of 400 x 400 is used to display the viewable area of the scrolling game world. Every in-game object is a vector drawn shape that is drawn into a BitmapData and then rotated or faded with a Matrix transformation to create arrays of BitmapData animations. The vectors for rotational movement are stored in a look-up table, and many memory and processor saving hints are thrown in for good measure. I cover object pooling, event reuse, "pools of one", and much more. The pool size for particles and the number of particles per explosion can be set be dynamically based on the profiled frame rate. This way users on better systems can get more ZarJaz out of the game. There is a lot more in this chapter such as a new object hierarchy for objects blitted from arrays, and a library class that creates those rotational arrays of blitted objects and alpha fade-outs. This chapter also covers small things such as adding a universal pause and mute functionality to the frame work. All of the classes and explanation necessary came out in just under 80 MS Word pages. I have no idea how many that will be in the book. I assume more.
We have one more to go, and then it is re-writes and "what the fuck were we thinking back then" questions as we re-read and revise the whole thing multiple times for release.
Should be fun...
This is great! The same Bruce who is fighing off a libel lawsuit aginast makers of Evony (read: Bruce appears to be the victim in this one) has a new article called You don't want to work in the video game industry where he lists 12 really good reasons why you should look elsewhere for employment. My favorites:
You can read the rest here: You don't want to work in the video game industry
Indie Flash Game Development Inter-Web Mash-up: November 12, 2009 (including Mochi Reviews)
This week I have paid some extra attention to checking out the games by some of my favorite developers (Robot Jam, Long Animals, and Alillm). I also have a set of Mochi game reviews and a lot of cool links from a variety of sites.
Sites, Blogs, Etc
What's new with Long Animals and Robot Jam?
I have been off writing my book with Steve and have not had much to to keep in contact with my all favorite developers. Robot Jam and Long Animals always have good stuff coming out. Run Bobby Run (LongAnimals) is a game I had the pleasure of testing out early in it infancy. It is a very fun little "protection game" mixed with an arcade shooter. I'm pretty sure Julian was an ST and Amiga developer back in the day. Check out Gravity Pig for a little beasties game the even Minter would be proud of.Over at Robot Jam (they work together a lot also), there is a new Blog entry up for Sniper Year 2. This puzzle solving, sniping shooter is a must play!
Run Bobby Run in action
What's new with Alillm Games?
Alistair Maunder is another great game designer / developer who basically makes all of game types that I love. Check out the splendid Pyroblossom for a taste. Rage mode has the Zar Jaz (see pic below)! The music is particularly cool. Hash is also a relatively new little retro arcader that I find my self going back to all the time.
Pyroblossom in action
What Iain up to?
Iain has a very cool blog post up on using GIT and GITHUB for source control Windows (I needed this today!!!). He also reviews Bloodwych for the Atari ST and Amiga. Steve and I had this game and played the hell out of it in 1990. Also, Iain is probably kicking himself for agreeing to be the tech reviewer for our book because the first few chapters (the ones he has) were a complete slog to write. They were the first ones and they are all over the map. I assume they are a complete slog to read and will need multiple revisions before they become readable. Sorry Iain.
Little Fits Of Zar Jaz::
- A little Silver Light Gaming Anyone? How about Avios, a Wings Of Fury (classic 8-bit 80's computer game) clone. Much effort was put into this one. There are a lot of control keys, but it should be worth your time if you played the original.
- Dave Munsie (Atari ST PD game god) has a couple new Christmas demos games up on his site.
- Flash Chaz has posted the Mochi Bot stats for his Captain Crash game.
- I still can't wait to heap praise of Squize's Ionic...
- Richard Davey let's us in on the secret location of some sweet sweet ear candy...
- Allen Chou (CJ) has a nice Push Button Engine game demo
- Emanuele has an interesting case study of a game (Bomb Digger) that gives the player extra features if played on the official site.
- Free Actionscript's Player Movement With Velocity (free code).
Mochi Game Reviews:
Classic Pacman: How much more wrong can one game be? This is the Neave version of Pacman with his credit removed. Also, good luck not being sued by Namco.
Grade: 0% Retrotastic
Flalls: The sweet little game is like a reverse version of pong. You have a moveable "blade of grass" in the middle of the screen with a opening. On each side of the opening are a blue and and orange homes for your Flalls. Your job is to move the blade of grass and let the correct color Flalls move to their home side of the screen. This is a well crafted deceptively fun little game.
Grade 80% Retrotastic
The Bubbles Strike Back: This is a Pang! like game. It looks pretty good for what is there, but isn't deep enough to really make a splash. I had fun playing it for a few minutes though, and the idea is a good one.
Grade 70% Retrotastic
Galaxy Wars: For the sake of the universe: Galaxy Wars is a very well done action / arcade game where you must protect the planet and your ship with a rotating orb that must be flung (physics-based) at enemy targets. The entire package is very high quality, but I just couldn't find a way for the controls to make the game fun. Something was lost for me, but I am sure others will find it to be a cool title.
Grade 80% Retrotastic
Running Free: Running Free is a simple, but well made little black and white stick figure platform running game. There certainly are many games like this out there, and this one doesn't add much that is new. There are 100's of Asteroids clones too, and I play each one for its own merits, so this genre should be no different. I had a fun few minutes with it, but wish I could "double jump".
Grade 82% Retrotastic
What's new at 8bitrocket?
- Flash Game Distribution Reviews via video podcast.
- Updates to the Sleep-Based Active Render Game Timer Loop
- Mochi Game Reviews via video podcast
- Using CamStudio to record Flash game play video
- SFXR does not work on Win 7, but does in HTML (AS3) and on the Mac
As always, www.flashgameblogs.com for your daily dose.
Optimized Game Timer Loop Update #2
Ok, so I spent the weekend (well the free-time part anyway), looking at the timer and found that in its current form it works best at 30FPS across all platforms. With updateAfterEvent turned on, you might still run the risk of an older computer with a new FP10 plugin not working (in the future), but so far this configuration works fine on all systems I tested,
I am not content though, so for now, if you are using the Sleep Based Active Render Game Loop Timer with a frame rate above 30, then I suggest turning off the updateAfterEvent and replacing it with stage.invalidate(). This doesn't seem to have the exact same smoothing reaction as updateAfterEvent, and it might just be a placebo, but it makes me feel better to have something it its place for for now.
Also, it is best (like I said up above) to try to keep the FPS at 30 with or without the updateAfterEvent turned on.
Now, I did work on 6 different timers in an attempt to profile a game while running and reset the frame rate and or turn off UpdateAfterEvent dynamically. It actually worked, but while the game played the FPS would continue to drop to the minimum I set no matter what I tried. This is because it never knew exactly when the game-play started or how long to continue profiling before it was satisfied. It just began profiling as soon as the application started (even on the menu screens). I keep my render loop and my game code decoupled and to continue to do this, I didn't want them to know too much about the state of the other. I added code to wait a specified number of frames and then lock in the current frame rate. This seemed to work if the player started the game up right away, but if the player sat on the title screen for too long of a time, then the render profiler would assume the game was fine and when the player got to the game it would not profile any more. Yes, I *could* have hard-coded it to start when the game play started. I began to do this, but stopped when I realized that if I added in a processor intensive menu screen or opening animation, the game might freeze before the profiling even began.
So, I will be modifying the timer to add in a game independent profiler that will start as the game begins (before menus and intros, etc) and use the first few seconds to profile the system off screen and choose an appropriate frame rate. If the frame rate is lower than my selected minimum, then I will turn off the updateAfterEvent. This complete version will be in the book if it works. I will also post a tutorial here on how to use it properly.
For now though, I am going to stick with the 30FPS max and the updateAfterEvent turned on until I have a working dynamic profiler.
******* Contents os Original Post
About a year and a half ago I posted a tutorial on using an optimized sleep-based game timer loop that included a time slice active renderer. The idea came from the great book, Killer Game Programming in Java, and the AS3 version was perfected by my good friend Chris Cutler and I. Soon after posting this tutorial, I began to get some reports of isolated incidents of it not working properly with the "updateAfterEvent" turned on for the Timer instance. This was isolated to just the Mac Flash CS2 IDE and was mitigated by lowering the frame rate down to 40FPS, so I shrugged it off.
Lately though, I have had to turn the updateAfterEvent off for more and more plug-in variations and now it even affects some games in XP and Windows 7. Those games need to be really pushing the limit of the Flash player to exhibit a problem, but since those are the types of games I like to make, and since the book we are writing focuses a lot of attention on this timer, I have decided to work on a patch this weekend.
I can't guarantee that is will be completely stable by Sunday, but it is affecting the book deadline so it will need to be fixed fast. Anyone who has seen the silky smooth screen updates using the active renderer with "updateAfterEvent" turned on, and then had to experience it without will appreciate what I am going to attempt to do.
My plan is to have the render loop profile its own attributes (while running the game) to auto discover when it is causing a problem in a player. When it does, it will either automatically turn off the "updateAfterEvent" or it will go further and attempt to realign the frame rate to one that is more compatible with the platform it is running on.
I hope this works...
8bitrocket Mochi Game Review Pocast: 11/06/09 We review about 8 games, and Steve touches his hair far too often, as we both never look into the camera because we are looking at a laptop to see the goods. Still, the new gameplay overlay screens are pretty cool.
We have found the need to take screen animations of our games lately, but were at a loss on how to do it cheaply and easily. That was until last week, when we found CamStudio, an Open Source utility for capturing video.
CamStudio is a very interesting piece of software. It is available for Windows only, which is a slight downfall (fire-up those Windows XP Bootcamp partitions Mac Lovers), but the benefits far outweigh the trouble of setting it up.
After you have downloaded and installed the program from CamStudio.org, launch it and you will see this screen.
The most important button is the big red circle. This will start recording. Before you press that button, find a Flash game you would like to record. Preferably one with a title screen, and launch it. This can be stand-alone, in a web page, or even in the IDE.
Once you have launched the game, press the record button. At this point you will get the ability to select the part of the screen you want to record. You can drag the window around the viewable game play area of your Flash Game. Be careful, once to lift the left-mouse button, recording will start immediately.
Notice also, that this works best for a game with a title screen because it will give you the necessary time to select the area you want to record before the game starts. However, this also means that the title screen will get recorded, as will any mouse clicks (this included the cursor) necessary to start the game.
Once recording starts, you will see green "L" (rotated on the corners) shaped icons surrounding the window that is being recorded. This will give you a good idea of what you will see when you are finished. CamStudio will also now display the following window.
This is a diagnostic display of the current recording. This will give you a good idea of the progress of your video capture.
After you have played through a portion of your game and are ready to stop recording, click the stop button. You will then be give n the opportunity to save the the file as an .avi.
The video can now be uploaded and used (YouTube.com for instance). Below is the raw video I took 20 minutes ago from SpaceEggs with CamStudio.
Video Of Space Eggs:
One of the drawbacks of CamStudio is that it will not record audio directly from your game. It does allow you to record from your speakers or microphone, but I could never get it to work correctly. My advice ti s to play with these features to see what worked bets for you.
Anyway, the raw CamStudio .avi is fine for a short video, but you also might want to edit it,, combine multiple videos, add music, etc. For this you will need a 3rd party piece of software. If you are a Mac User you can try iMovie, which is just OK, but free, so go for it! As far as Open Source goes, jahshaka seems to be the most advanced product, but it also has not been updated in over a year, and it's status seems a bit doubtful. For Windows you can look at Virtual Dub, but it lacks a lot of the editing and compositing featuring you might need to finish your project
My advice is to look beyond Open Source tools, and either fire-up your Windows XP PC (or your now useful Mac Bootcamp partition that sports CamStudio), and purchase a copy of Sony Vegas. The cheapest version is $39.99 (the pro is over $500), but it is WELL WORTH the price. Vegas uses the Sony Acid-style loop interface to create video, and once I got get the hang of it, it's the best tool I've ever used The cheap version allows for 4 video tracks, and 4 audio tracks. This is more than enough to composite, blue-screen (chroma-key), alpha-blend video overlays, create titles, etc.
The screen above is what the interface looks like. The "tracking" nature of the product is what makes it so easy to use. If you don't believe me, you can download a free trial to see for yourself. I get no benefit from Sony for saying any of this, I just LOVE the audio and video products the acquired from Sonic Foundry, and Vegas is one of them. Below is the produced demo real I made using CamStudio to capture the video, and Sony Vegas to edit it. This video contains 70+ different clips taken with CamStudio, all compiled and edited in-place with Sony Vegas. I made this in about 2 hours using both products.
By the way, it's interesting to note the reason why CamStudio exists in the first place. The web site for the product details some of it's history. This should be very Interesting to long-time Flash developers:
CamStudio was originally released by a company called RenderSoft who were subsequently bought by a company called eHelp who used some of the technology in their program, RoboDemo ...
Some time later, eHelp was bought by Macromedia who wanted RoboDemo (which was to become Captivate) ...
Knowing that CamStudio did some of the stuff RoboDemo did for free (mainly export to streaming Flash), it looks like they released a newer version of CamStudio (2.1) which fixed some bugs but most importantly, removed certain features. Gone was the ability to create SWFs, added was the requirement to register to use it, and over time, links to the various webpages that had CamStudio and its source code, became broken.
You read the rest on the CamStudio.org web site.
SFXR native in Mac OS and AS3!
I installed Windows 7 on my Bootcamp drive this last weekend. There were a few pitfalls, such as getting BlueTooth devices to work properly (black magic), but it was mostly painless. To start up work on the games book again, I needed to re-install all of my usual development tools. Everything from FlashDevelop to Paint.net worked fine, with the exception of the wonderful 8-bit sound generator, SFXR. Originally created by DrPetter for a Ludum Dare weekend game contest over 2 years ago, this incredible tool has now been ported to multiple platforms, including MAC OS and AS3! No longer do I have to rely on Windows for all of my best free tools.
The great site, Woolyss Chipmusic, has a zip of all the version ports for you to play with.
You can use the AS3 version online without downloading anything. Written by Tomas Pettersson, you can read all about it on the great SuperFlashBrothers blog. Plus, the code is open source, so you can add sound generation directly to your own games.
Sweet Sweet 8-bit Zarjaz!
Indie Flash Game Development Inter-Web Mash-up: November 3, 2009 (including Flash Game Distribution Reviews)
Indie Flash Game Development Inter-Web Mash-up: November 3, 2009 (including Flash Game Distribution Reviews)
There is a lot of cool new stuff to cover, so with no further delay here is a survey of my favorite sites, games, and blogs. We start with some Flash Game Distribution reviews:
Flash Game Distribution Reviews:
Game of The Week: Zip Zap
Zip Zap is an awesome classic Defender style arcade game with a style and presentation all it own. Sweet sweet Zar Jaz!
Grade: 90% Retrotastic!
-Rag Doll Pirates: Fire cannon balls at attacking pirates. The music, SFX and presentation are high quality. The game is pretty fun.
Grade 80% Retrotastic
-Spectromancer: A very made crafted card battle game that looks like a PC game. The file is large, but the presentation is well worth the wait.
Grade 85% Retrotastic.
-Mad Jack's Pumpkin Bash: A well made little retro style dodging game with 8-bit graphics, nice sounds and a Halloween theme.
Grade 75% Retrotastic
-zBall: A scrolling physics-based action game. Bounce the ball down the hills made up of retro style outdoor platforms. It's well made, but difficult.
Grade 74% Retrotastic
-Death Wizard: This action, adventure, side scrolling, shooter / platformer / beat-em-up with magical powers has pretty much everything you could want in a free action game. It looks and plays a little like an ST or Amiga gem.
Grade: 85% Retrotastic.
Sites, Blogs, Etc
GamingYourWay.com: Squize and nGfx have been busy with some interesting updates lately. First we have a Flash tutorial on how to do the George Lucas style screen transition wipes from the original Star Wars movie. Next, try out their awesome physics-based smash 'em up, Destroy All Cars. Squize's work in progress on Ionic looks amazing and I can't wait top play. It has Megadrive and Amiga written all over it. The logo is very sweet as well. It certainly doesn't have that "Hey guys, I made this in my warez version of Flash CS4", now does it. These guys know their shit backwards, forwards, inside and out.
PhotonStorm.com: Richard has posted the much needed (by me) beginner's guide to Christian Corti's AS3 SoundTracker library, FLOD. The examples can be used in Flex/Flash Develop or in the Flash IDE to control playback and process Amiga MOD files. Also, Richard's excellent Kyobi game (re-titled Touch & Go) is now a free iPhone game.
FreelanceFlashGames.com has a post on the cool Pulse Multiplayer Games API. This seems to be a lot like Electrotank's EUP.
UrbanSqual.com has a brand new game they designed for Ubisoft called Rabbids To The Moon. This is a K-RAZY awesome game in the Rabbid's universe where you are tasked with collecting as much human junk as you can to build a tower to the moon.
EmanueleFeronato.com has the usual incredible selection of great posts on subject like: Social Gold's new in-game payments system. and tutorials on how to make a Stabilize style game in Box2D (part 1 and part 2).
FreeActionscript.com is been updated with some cool useful general Flash trinkets like: Centering A MovieClip based on browser size, Creating a simple accordion menu. There is also a very nice little post on what software you can choose from to make games and Flash/Flex applications when moving from AS2 to AS3. Also Happy Birthday, FreeActionscript.com!
blog.iainlobb.com: Iain just posted the Game Developers Radio Podcast - Flash Games Design Special that includes him, Ryan Hensen Creighton, Daniel Cook, and Edmund McMillen.
Untoldentertainment.com: Speaking of Ryan Hensen, he has posted a very well done and useful piece on creating your own game studio: Running a Game Studio: From Start-Up to Sustainability.
-Mochi's Flash Game Friday turns into a Monthly contest;
-Flash games on cell phone memory cards;
-If you have some spare time and want to make .000001 per hour, how about applying for this $100 offer to make a Street Fighter Clone in Flash. Ridiculous.
As always, www.flashgameblogs.com for your daily dose.