Category Archives: Blog

Tutorial: Resample Bitmaps in Flash AS3

Often I find working with Bitmaps and BitmapData in Flash can be cumbersome. Simple things such as resizing images can require a lot of code. For this tutorial i have created a “BitmapResampler” class to help makes things easier. This class can be useful for things such as creating dynamic thumbnails, taking Bitmap snapshots of Movie Clips or TextFields, or resampling game graphics at run-time.

Here comes the code:

	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.IBitmapDrawable;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	public class BitmapResampler
		public function BitmapResampler( ) { }
		//returns a BitmapData Instance of the image of the source DisplayObject / BitmapData
		public static function getResampledBitmapData( source : IBitmapDrawable , width : Number , height : Number ) : BitmapData {
		var sourceBitmapData : BitmapData;
		if ( source is DisplayObject ) { // if source is a DisplayObject instance
				sourceBitmapData  = getBitmapDataFromDisplayObject( DisplayObject( source )  );
		}else if ( source is BitmapData) { // if source is a BitmapData instance
				sourceBitmapData = source as BitmapData;
		}else { // break on unhandled source
				return null; 
		//set the scale for the draw operation, for the new width / height
		var matrix : Matrix =  new Matrix();
		matrix.scale( width / sourceBitmapData.width  , height / sourceBitmapData.height );
		//create the resized bitmap data
		var ouputBitmapData : BitmapData = new BitmapData( width, height , true , 0x00000000 );
		//draw the source to the bitmapData instance
		ouputBitmapData.draw( sourceBitmapData , matrix , null , null , null , true );
		//dispose of temporary bitmap data
		if ( source is DisplayObject ) sourceBitmapData.dispose();
		return ouputBitmapData;
		//returns a Bitmap of the image of the source DisplayObject / BitmapData
		public static function getResampledBitmap( source : IBitmapDrawable , width : Number , height : Number ) : Bitmap {
			var bmp : Bitmap = new Bitmap( getResampledBitmapData( source , width, height ) );
			bmp.smoothing = true;
			return bmp;
		// this function will create a BitmapData instance which contains the image of the source DisplayObject
		// note : transformations will be reset
		protected static function getBitmapDataFromDisplayObject( source : DisplayObject ) : BitmapData {
			//get the rectangle of the image data in the DisplayObject
			var sourceRect : Rectangle = DisplayObject( source ).getBounds( DisplayObject( source ) );
			//create a BitmapData instance to draw the DisplayObject to
			var bitmapData : BitmapData = new BitmapData( sourceRect.width , sourceRect.height , true , 0x000000000 );
			//draw the portion of the clip that contains image data
			var matrix : Matrix = new Matrix();
			matrix.translate( -sourceRect.x , -sourceRect.y );
			bitmapData.draw( source , matrix , null , null , null , true );
			return bitmapData;

Using this class is pretty simple. Just call BitmapResampler.getResampledBitmap or BitmapResampler.getResampledBitmapData with your image source and the width / height:

//takes a snapshot of the displayObject, and returns a Bitmap 200 x 200
var bmpFromDisplayObj : Bitmap = BitmapResampler.getResampledBitmap( new TestDisplayObject() , 200 , 200);
bmpFromDisplayObj.x = 10;
bmpFromDisplayObj.y = 10;
addChild( bmpFromDisplayObj );
//resamples the BitmapData instance and returns a BitmapData 150 x 300
var bmpFromBitmapData : Bitmap =  BitmapResampler.getResampledBitmap( new TestBitmapData( 0, 0 ) , 150 , 300 );
bmpFromBitmapData.x = 310;
bmpFromBitmapData.y = 10;
addChild( bmpFromBitmapData );

Files for this tutorial can be found here.

For more Flash AS3 Tutorials and a pile of other useful stuff, check out our Flash and Actionscript 911 feature.

De Fine Balance

Every year, the organizers of TOJam (the city’s annual orgiastic game design bacchanal) choose a theme to guide the goings-on. Last year’s theme was CHEESE. Most of the Jam’s participants took the directive literally. There were games about blasting towers of cheese, games about digging through cheesy substrata, and games about entire seas of cheese. Entire seas of em!

i was a little surprised that no one went for the broader definition of cheese, a la “camp” or “corn”.

This year’s theme is SCALE, which offers many more possibilities. i thought i’d run down the different uses of the word to provide this year’s Jammers with some inspiration:

1. To Climb

Make a game about:

  • scaling a building (Rampage, anyone?)
  • scaling a wall (like Achilles in the Trojan War! … or Spider-Man, for you plebs)
  • scaling a rock face of a mountain

2. A Horny Skin Plate

Make a game about:

  • a snake!
  • a lizard!
  • a fish!
  • a pangolin! Because they’re weird.

3. To remove plaque from the teeth.

Make a game about:

  • An amateur dentist (i think Adult Swim already did this, but i can’t find the link)

4. A device for weighing things.

Make a game about:

  • Weighing things! (the best example i can think of is at VectorPark – click the icon with the snowman)
  • the astrological Libra sign is a pair of scales. Some kind of horoscope game/
  • the figure of blind justice holds a pair of scales
  • the Wii Balance Board is a (barely) high-tech bathroom scale

Blind Justice

Couldn’t you see Blind Justice kickin’ ass in a God of War-style game?

5. A representation of proportionate size.

This is the one that comes to mind most naturally, i think. Make a game about:

  • things that are big and things that are little. (yawn)
  • i dunno. This is the most obvious one, so it’s the least appealing to me.

6. A graduated system of wages or rates.

As in “pay scale”. Do a game about:

  • Santa’s elves viciously competing for corporate bonuses
  • a union worker bumping off employees with more seniority so that he can earn a higher wage
  • a tycoon game about managing the wages of sweatshop workers

7. An ordered progression of musical notes.

Make a game about:

  • That scene from the Sound of Music where Julie Andrews teaches the children to sing “do re me”. ACTION-PACKED!!
  • Some crazy avoid-the-obstacle game that takes place on top of a gigantic piano keyboard. Remember Bumble Boogie?

There are other definitions, i’m sure. My point is that before you do some take on Shadow of the Colossus this weekend at the Jam, consider your options! They are many and varied.

TOJam is this weekend, May 1-3 2009 in Toronto. Spots are limited, so sign up now!

Smokin’ Poll

NOT THAT WE ARE … but if we WERE creating an online multiplayer trivia game, WHICH WE MAY NOT EVEN BE DOING, we wanted to present a poll where you choose your FAVOURITE trivia categories. The results of this poll MAY or MAY NOT be used for our hypothetical online multiplayer trivia game, which is as tangible and likely as a TAPDANCING UNICORN at this point. We’re not saying either way.

Question Mark

[poll id="3"]

Embattled Game Developer Makes Impassioned Plea for Government Assistance

TORONTO – The president of struggling small game development studio Untold Entertainment Inc. made an impassioned plea on the steps of the Ontario Legislative Building today. Ryan Henson Creighton, the company’s beleagured founder and occasional mascot, was seen feebly raising his arms toward the towering Queen’s Park structure. With tears streaming down his cheeks, Creighton wailed “Running a business is hard!” Heaving and sobbing himself into a crumpled heap on the steps, his mouth pulled taut across his face in a grotesque grimace, he begged in a stage whisper “Please give me some moneys.”

Untold Entertainment Inc., the Ontario-based start-up, has been creating online Flash games for a year and a half. Prior to starting the company, Creighton worked a cushy job at a large Canadian media conglomorate, creating web games that sold sugar cereals to increasingly obese children. When we interviewed Ryan Henson Creighton a month ago, the cracks were already starting to show.

“I started this business to find myself, you know?” The video game designer tapped his foot nervously against the secondhand Herman Miller Aeron chair that he purchased from a seller on Craigslist. “But, I mean, if you run out of money, what are you supposed to do then? I see banks and car companies lobbying the government for assistance, saying if they don’t get the money, they’ll go out of business. Is that what the government wants? Do they really want me to go out of business?”

Looking around Untold Entertainment’s Yorkville headquarters, it’s easy to see where Creighton went wrong. High overhead costs, coupled with an apparent penchant for shelled pistachio nuts – the carcasses of which littered the floor of the tiny 110 square foot office – have driven the game company’s profit margins into the red. The insistence of Untold’s clientele to use their own internal artists, many of whom were hired directly from art school or enticed from the street with half-eaten bag lunches, strip Untold Entertainment of control over the games they produce. The result is a portfolio comprised of client-led game designs propped up with lacklustre junior-level artwork. Many of the company’s finished projects are notably absent from their portfolio site.

A Focus on Original Content

When the client worked dried up due to the economic downturn in early 2009, Creighton devised a new strategy. “We’re going to develop original content,” he said with an unsettling flash in his eye. The company’s only original content to date has been comprised of a handful of titles built for the free-to-play online model, where the game developer either releases the product freely without receiving compensation, or scrapes ad revenue leftovers from various online monetization schemes like Kongregate and MochiAds.

Creighton’s trademark ambition quickly materialized as he described his upcoming game. “It’s called Kahoots!” he said wildly, his left eye twitching as he pronounced the “K” in the game’s title. “And it’s all made in clay, see?” At this point, Creighton held up a lump of modelling clay that resembled a folding chair – or a dragon – and continuned, “We’re gonna release it for the PC and the iPhone. And the main character is going to be voiced by this African choir, all talking at once, so it sounds all freaky, you know? Then we’re going to film some explosions and put them in the game in spots where you earn extra points. Cause regular games, they use particle systems, right? But we’re gonna use real explosions, ’cause real explosions are better.”

The increasingly enthusiastic developer went on to describe Kahoots for an additional two hours, explaining the symbolism behind the game characters’ moustaches, and his justification for importing all of his modelling clay from Iceland. When we finally left the tiny office, Creighton was still talking, and apparently didn’t notice we were gone.

Request for a Bail-Out

By April 2009, Creighton’s ambition remained strong, but his funding well had run dry. Somewhere between hiring a famous troupe of New York kickline dancers to record foley sound effects for Kahoots, and starting into a full-scale clay model of the city of London, one of his cheques bounced. It was the first tangible sign that Untold Entertainment was in dire straits.

We caught up with Creighton in front of the Ontario Legislative buildings at Queen’s Park in Toronto, where he had asked us to meet him to cover what he called his “bold gesture”. Within minutes, the frail and defeated mass of Creighton’s body laid shivering on the cold stone steps. A protest sign, scrawled with the slogan “Please give me $3047.62″, sat discarded on the lawn.

No one else seemed to take account of, or even notice, Creighton’s break-down. At one point, an officious-looking man in a camel hair coat strode from the front doors of the building and stepped over Creighton’s body without noticing he was there; when interviewed later, he explained that he had been there applying for a photography permit for his daughter’s wedding on Saturday.

A Social Responsibility

Ryan Henson Creighton’s request for government funding – a sum totalling in the thousands – raises the question of whether or not it is the Canadian government’s responsibility to provide assistance to tiny, arguably insignificant companies, even as it faces pressure from the media and automotive sectors. Despite his request falling on deaf ears, Creighton has resolved to bring the dispute as far as Ottawa, where he’s pledged to bring a box of tissues to carry him through his next daring indictment of the flagging Canadian free market economy.

Toronto Hand Eye Society’s Sophomoric Outing

The Hand Eye Society is a new Toronto special interest group, specially interested in exactly what, i don’t know. Noted crazy person Jimmy McGinley invited me to speak about Kahoots™, our upcoming fun crime-themed puzzle game, at the group’s second session this Thursday April 23rd at 7:00 PM.


Freaky eye image, unabashedly stolen from the Hand Eye Society site. (“Hand” was nowhere to be found.)

As the website states, “the audience will be required to interact, and the only goal is excitement.” To that end, i’m planning to punch every audience member in the face.

Come out and see what the fuss is about. Paparazzi alert: i’m liable to show my beav climbing out of a limo.