AS3 Earthquake Class v1.0
I’ve noticed that there are a lot of small things that can save you time when designing and coding a game. Stuff that wouldn’t take long to code, but if someone’s already done it, why bother?
So in that glorious spirit of apathy, I present to you the Pixelwelders Earthquake class. This is just a simple little class that allows you to create an earthquake (or explosion, or invasion, or whatever) in your game. You just feed it a DisplayObject, the intensity of the quake, and the duration in seconds, and voilá. This is the syntax:
Earthquake.go( displayObject:DisplayObject, intensity:Number, seconds:Number ): void
And this is a two-line example:
import com.pixelwelders.fx.Earthquake;
Earthquake.go( gojira, 10, 1 );
And this is the result. Notice that each time you click, the earthquake is slightly different. Scroll down to download the class.
Download the class (and the above example) here.
Tags: Actionscript, earthquake
March 25th, 2008 at 11:41 am
You sure love singletons.
March 25th, 2008 at 3:12 pm
Well, I do love Singletons, but this is just a static class. It seemed easier to use that way.
March 27th, 2008 at 1:55 pm
Blast, I just assumed. I’ll download it now, and every piece of code from now on! Gotta catch ‘em all! Gotta catch ‘em all!
March 27th, 2008 at 4:43 pm
You’ve probably already got something that does this. I’ve just noticed that I always tend to make some sort of “screen shake” class for every game. This was just me making something reusable. It’s really not very complicated- just well-encapsulated.
February 2nd, 2009 at 10:38 am
put your classin one of my games dude. tasty.
February 16th, 2009 at 5:09 am
Thx for sharing I added this method :
public static function stop(): void {
if ( timer )
{
timer.stop();
cleanup();
}
}
and I call it in go(…) also, is solves a bug when you call go on a different displayobject before the earthquake is complete on the first DisplayObject (the first DO was kept in wrong coordinates).
public static function go( _image:DisplayObject, _intensity:Number = 10, _seconds:Number = 1 ): void {
stop();
…
May 25th, 2009 at 12:27 am
I like this however when I call go again before it completes it does not reset to the default position. Is it not supposed to do this?
July 6th, 2009 at 12:46 pm
Brilliant! Can this be extended to include more than 1 display object. I’m going to try. Thanks!