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.
You sure love singletons.
Well, I do love Singletons, but this is just a static class. It seemed easier to use that way.
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!
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.
put your classin one of my games dude. tasty.
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();
…
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?
Brilliant! Can this be extended to include more than 1 display object. I’m going to try. Thanks!