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.