Explosions

posted in Beals Software
Published November 05, 2009
Advertisement
I've been working on the animation system for my code base and working it into Invasion. The renderer hasn't been optimized yet (simple primitive/texture batching; uses DrawUserPrimitives()), but it does well enough:

10k explosion animations running at a steady (average) 231 FPS (about 44 FPS with vertical-sync enabled.)

Here's the animation file for it:
"1.0"
?>
"Explosion" FrameDelay="0.025">

"0">
"32" Y="32" />
"explosion.png" />
"0" Y="0" Width="64" Height="64" />


"1">
"32" Y="32" />
"explosion.png" />
"64" Y="0" Width="64" Height="64" />


"2">
"32" Y="32" />
"explosion.png" />
"128" Y="0" Width="64" Height="64" />


"3">
"32" Y="32" />
"explosion.png" />
"192" Y="0" Width="64" Height="64" />


"4">
"32" Y="32" />
"explosion.png" />
"256" Y="0" Width="64" Height="64" />

"5">
"32" Y="32" />
"explosion.png" />
"0" Y="64" Width="64" Height="64" />


"6">
"32" Y="32" />
"explosion.png" />
"64" Y="64" Width="64" Height="64" />


"7">
"32" Y="32" />
"explosion.png" />
"128" Y="64" Width="64" Height="64" />


"8">
"32" Y="32" />
"explosion.png" />
"192" Y="64" Width="64" Height="64" />


"9">
"32" Y="32" />
"explosion.png" />
"256" Y="64" Width="64" Height="64" />

"10">
"32" Y="32" />
"explosion.png" />
"0" Y="128" Width="64" Height="64" />


"11">
"32" Y="32" />
"explosion.png" />
"64" Y="128" Width="64" Height="64" />


"12">
"32" Y="32" />
"explosion.png" />
"128" Y="128" Width="64" Height="64" />


"13">
"32" Y="32" />
"explosion.png" />
"192" Y="128" Width="64" Height="64" />


"14">
"32" Y="32" />
"explosion.png" />
"256" Y="128" Width="64" Height="64" />

"15">
"32" Y="32" />
"explosion.png" />
"0" Y="192" Width="64" Height="64" />


"16">
"32" Y="32" />
"explosion.png" />
"64" Y="192" Width="64" Height="64" />


"17">
"32" Y="32" />
"explosion.png" />
"128" Y="192" Width="64" Height="64" />


"18">
"32" Y="32" />
"explosion.png" />
"192" Y="192" Width="64" Height="64" />


"19">
"32" Y="32" />
"explosion.png" />
"256" Y="192" Width="64" Height="64" />


"20">
"32" Y="32" />
"explosion.png" />
"0" Y="256" Width="64" Height="64" />


"21">
"32" Y="32" />
"explosion.png" />
"64" Y="256" Width="64" Height="64" />


"22">
"32" Y="32" />
"explosion.png" />
"128" Y="256" Width="64" Height="64" />







And the associated image (I used the generator from this page to generate it):


As with my previous animation system it's separated into two classes: Animation and AnimationController. You can either load an animation from a file or use it's AddFrame() method to programmatically create one.

The controller has 3 important methods: Play(), Update(), and Stop(). Play() takes an Animation instance and a Loopstyle (None, Normal, or Reverting), Update() takes the frame-delta, and Stop() takes no arguments.

I thought about implementing a pause system, but I don't see any reason to pause single elements (you would pause the entire game, which can easily be done through "GameTime.SetScale(float)". Passing 0.0f to this effectively pauses all of the logic.)

Anyway, back to work.

[edit]
I was hoping to get a lot more done before heading to bed, but I didn't lol. I spent most of the night playing with the system, testing out the loop styles and whatnot. Did find a large issue; after adding a certain amount of vertices (turned out to be every 1334 vertices) it would render one quad incorrectly (no texture.) Took a little while to track it down; I couldn't isolate the quad (as that fixed it), no invalid textures were detected at any point, and I couldn't pin-point a position. After about an hour or so, I figured out that it was because I had forgotten to check if an incoming value was null before assigning it.

Actually, I found two large issues. I have a class named PerSecondTracker that tracks a value and averages it (use it for my frame-rate counter, batches/second, stuff like that.) Well, I use a list so that I can dynamically change the size of the average list, which was supposed to have a default length of 50. I started to realize that, if I let my program sit there, the frame rate just kept degrading. I step through the code just to realize I had forgotten to control the length of the list, so it just kept growing and growing (though, I have to say, I don't think 24FPS is bad for averaging a list of over 100k values and rendering 10k sprites with barely optimizations lol.)

Beyond that, about the only thing I got accomplished is migrating Animation and AnimationController from the engine and into my code base. I revised them both a little (Animation had stuff it didn't need, like a Name variable and a GraphicsDevice. AnimationController didn't change any, but I had a bug in it.)

I also added a static method to Animation to simplify generating one from an image containing a sprite sheet.

Meh, time for bed. I have to work tomorrow.
Previous Entry Movement Schemes and AI
Next Entry Untitled
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement