Archive | ActionScript RSS feed for this section

The results of my annual “code something different this Christmas” idea.

It’s becoming something of a tradition now I guess, but once I’ve allocated that extra Christmas holiday time appropriately, I find I have that little bit of extra time to devote to trying something new.  This year, I thought I’d try rewriting (again) one of my old university experiments.

Here’s the result:

It’s pretty.  I won’t even try to explain the idea behind it, but it’s basically an attempt at simple life simulation, with some AI governing the actions.  This time around I’ve built it with the aid of Box2D, so all the movement, impacts and interaction is achieved by punching some figures into the Box2D world, which makes the thing a helluva lot easier.

The big plus of “trying something new”? I now have a basic understanding of trigonometry!  I didn’t even have to Google anything!

Link: Name your loops

Name your loops

You can name your loops!  Okay, so it’s not very exciting, but naming your loops will make things so much easier to organise and understand – I expect.  Check out the link to read all about it;

http://blogs.adobe.com/cantrell/archives/2009/12/labels_in_actionscript_3.html

Cool ActionScript projects to try out, if you haven’t already…

Hopefully I’ll get a chance to cover each of these in more detail shortly, but there’s a whole bunch of cool new Actionscript 3 projects that are floating around at the moment – here are some of my favourites that I’m trying to find enough time to explore in detail.  Each stands out from the crowd for being pretty awesome, and I’m hoping to find some killer way to combine them into my projects.

For Animations & Tweening:

GreenSock Tweening Platform [link]
The name actually encompasses five different varieties of animation libraries, and is awesome at scripting individual and timeline animations.  Not just that, but it comes packed with a load of animation options that you didn’t know you wanted, until you see them.  Like realistic motion blur.  That one’s cool.  Especially once you’ve tried making it yourself in the past…

Clipboard data 04-11-09, 23-03-42

Game development

Collision Detection Kit [link]
Much like the GreenSock stuff, just how good this is really has to be seen to be believed.  The basic Actionscript hit-test tools were never really that great.  Sure they worked, but if you wanted anything more than a Boolean response, it was no good at all.  The Collision Detection Kit gives you enough information to do proper physics – working out things like what, where and how hard things hit.  It works with any display object – vectors, bitmaps, even video.

Clipboard data 04-11-09, 23-05-18

Box2D [link]
Box2D.  Runs blindingly fast, precisely calculates physics and interactions.  It’s a true physics engine, rather than others (like Collision Detection Kit) which are just imitating physics.  A little hard to get into because it’s all written differently to every other Actionscript example I’ve ever seen (“You must unlearn what you have learnt”) but once you get over that hurdle, it’s just so… powerful.

Clipboard data 04-11-09, 23-07-22

Documentation for Box2D isn’t very new user friendly, but Emanuele Feronato has a fantastic series of blog posts on Box2D which will prove invaluable.

Link: Cool Actionscript 3 ‘Genie’ effect

This is an awesome link that Mark sent around the other day – a cool Mac-esque ‘Genie’ effect.

GenieEffect

That effect is all very cool, but even more surprising is that it seems to be an Actionscripted effect, rather than a Pixel Bender effect.  You can find the blog post from the guy that created this here, and even better can find a live online example here.

Rotating BitmapData with Actionscript 3

Here’s a little snippet – rotating BitmapData (through 90 degrees) with Actionscript 3.

var matrix:Matrix = new Matrix();
matrix.translate(-bmd.width / 2, -bmd.height / 2);
matrix.rotate(90 * (Math.PI / 180));
matrix.translate(bmd.height / 2, bmd.width / 2);
var matriximage:BitmapData = new BitmapData(bmd.height, bmd.width, false, 0x00000000);
matriximage.draw(bmd, matrix);

The code above can rotate an images BitmapData, using a Matrix to transform the image when you draw the data.  It’s only really designed to rotate the image in 90 degree increments though – so be aware of that.

How it actually works is to create a new Matrix object, offset the source BitmapData’s width and height (so the rotation goes from the center of the bitmap), rotate the BitmapData, move the BitmapData again (to undo the previous offset), create a new BitmapData object to draw the rotated BitmapData into, and finally draw the source BitmapData with our newly created Matrix.

Simple.