Blit and Cache Movie Clips

by Michael Williams on February 28, 2010 · 1 comment

in Tutorial

BlittingPreview.png
On the left: a regular movie clip. On the right: three blitted clones.

“Blitting is a higher-performance alternative to using the built-in display list in Adobe Flash for drawing objects on the Stage. This technique involves copying the individual pixels of an existing image directly on to the screen—a bit like painting all of your game’s spaceships and monsters onto a canvas.”

From a tutorial I wrote for Adobe Developer Connection: Blitting and Caching Movie Clips in Flash.

It’s an introduction to blitting for developers using the Flash authoring environment (Flash IDE); you’ll learn how to take a regular movie clip from the library, cache it as a series of Bitmaps, and draw it (blit it) to the screen.

Why bother? Because to blit an object is much faster than to use addChild().

Click here to start reading. If you’ve got a free Adobe account, you can comment on the article itself; otherwise, feel free to ask any questions in the comments to this post :)

{ 1 comment }

Italian AS3 Avoider Game Tutorial

by Michael Williams on February 20, 2010 · 3 comments

in Avoider Game Extras, Guest Posts

English, Spanish, Polish, and now… Italian!

Francesco Malatesta is translating my AS3 Avoider Game Tutorial (itself based on an AS2 tutorial by Frozen Haddock) into Italian.

Ciao a tutti, mi chiamo Francesco e sono un ragazzo di 20 anni, studente di Economia Informatica. Adoro l’informatica e la programmazione. Ovviamente anche i videogiochi. Nel tempo ho cercato di fondere insieme queste passioni e flash si è rivelato uno degli strumenti più potenti per questo mio scopo, specie se si è alle prime armi e non si hanno molti fondi o strumenti.

I tutorial di Michael sono fantastici, ben strutturati e facili da seguire. Per questo motivo ho deciso di tradurli nella mia lingua e condividerli con tutti gli aspiranti programmatori di giochi del mio paese.

Click here to start reading.

Thanks, Francesco :)

{ 3 comments }

Optimisation is about making your code more efficient. Usually you’ll optimise for speed — not to make the gameplay faster, necessarily, but to keep the game running smoothly, with no lag.

(If your SWF is a few MB larger than you’d like, you’d want to optimise for size, but that’s a different topic for a different post.)

The hundreds of tricks and techniques to do this boil down to one principle:

Don’t make Flash do more work than it needs to

For example, suppose you have a line like this:

var newX:Number = ( 47 * Math.sin( Math.PI * 23 / 109 ) / 121.88 ) + player.x;

…and you run that line every tick or every frame. Look at all the work you’re making Flash do!

It’s got to get the value of pi and multiply it by 23, then divide that by 109, then get the sine of that number, then multiply that by 47, then divide it all by 121.88, and finally add the player’s x-position.

If you grab your calculator, you can find that 47 * Math.sin( Math.PI * 23 / 109 ) / 121.88 is 0.237317256. That’s not going to change; we don’t need to make Flash keep calculating that over and over again. So that line can be rewritten:

var newX:Number = 0.237317256 + player.x;

Suddenly, Flash has much less work to do — you’ve done the work for it.

Let’s look at some better examples… [click to read on…]

{ 25 comments }

Version Control with Git, Flash and AS3

by Michael Williams on February 3, 2010 · 13 comments

in Articles, Tutorial

Git Logo

Why Use Version Control?

Do any of these sound familiar?

  • You have a bunch of different folders called MyGame, MyGame-backup, MyGame-February, MyGame-finished, MyGame-bugFix, MyGame-Mochi, MyGame-Kong, …
  • You avoid deleting code in case you need it later, so you’ve got lines and lines of commented-out ActionScript, just in case
  • You’re reluctant to experiment with new code in case you screw something up and can’t undo it later

Version control helps with all that. It keeps track of all the changes you make and lets you move back and forth through all the different versions of your project, even if the differences between versions are only tiny. It also allows you to split off separate “branches” of your project and work on them alongside your main code, which is really useful if you need to make different versions of a game for different portals or sponsors.

If you collaborate on code with other people, then you already know how messy it can be trying to copy and paste each other’s changes to keep everyone in sync. Version control helps here too, by merging everyone’s changes together. OK, sure, if two people try to edit the same function at once, there’ll be problems — but at least this can be detected and dealt with quickly.

Once you get used to using version control (also known as source control or revision control), you’ll find other benefits appear. For example, simply getting into the habit of noting down all your changes (as VC requires you to do) can make you more productive, and encourage you to be more organised when tackling problems.

Right. So VC is great, no arguments there. If you’d like to know more about what it is, check out this excellent post over at BetterExplained. In this tutorial, I’ll show you how to get started using Git as a version control system for your Flash projects.

[click to read on…]

{ 13 comments }

New Site Design

January 26, 2010

Summary of the new site design.

6 comments Read the full article →

Review: Safari Books Online

January 20, 2010

I review Safari Books Online, “Netflix for books”.

23 comments Read the full article →

Multidimensional Arrays in AS3

January 13, 2010

Intro to 2D arrays, 3D arrays, and beyond, in AS3, using the “array-of-arrays” technique.

40 comments Read the full article →

Polish AS3 Avoider Game Tutorial

January 9, 2010

Learn to make Flash games with this Polish AS3 Avoider Game tutorial — translated by Marcin Horoszko.

1 comment Read the full article →