XNA Creators Club Online
Page 1 of 1 (13 items)
Sort Posts: Previous Next

Explosion Generator v2.1 (Sprite Sheet Generator)

Last post 8/21/2009 6:30 PM by araczynski. 12 replies.
  • 6/4/2009 7:01 AM

    Explosion Generator v2.1 (Sprite Sheet Generator)

    (Mods, if this post is in the wrong section, please help me choose a better one?  Thanks!)

    I'm sure that a lot of us who are trying to make a 2D game have struggled with making things blow up.  Having skills to be both artist and developer seems to be quite rare, and I am no exception to this.  Many of us have stumbled upon an old explosion sprite sheet generator written by Cliff Harris at http://www.positech.co.uk/content/explosion/explosiongenerator.html (and if you haven't, you have now!).  I looked at this, but the main problem I had with it was that whatever background color I used to generate the explosion animation would "seep" into the final drawing of my sprites, looking especially weird when drawn over another image.  As stated in the URL above, the source code has been lost and is no longer available.  I tried various ways to get the background to be completely transparent, but couldn't come up with anything (likely due to lack of knowledge) and pretty much wrote off the sprites as something I couldn't really use they way I intended.

    As I got to thinking about it more, I thought I might be able to re-write the sprite sheet generator that Mr. Harris wrote using the same base images he did.  I toyed around with it for a couple of days and have come up with an XNA 3.0 version that, while not an exact reproduction of his algorithms (how could they be?  noone has the source anymore), does a really good approximation of his explosions.  Mr. Harris was also kind enough to allow me to use and redistribute the textures used in the original explosion generator.

    Operating the app is pretty straightforward (all user input is handled in Game1.Update()), just press the space bar and it will generate a random explosion in a 64x64 pixel rectangle, store every 5th frame, then rewrite the stored frames into a 5x5 grid (sprite sheet) as a single texture.  When the explosion is complete, the sprite sheet will be displayed and immediately to the right of where the explosion was originally generated, a 30 FPS animation of the sprite sheet will loop so you can see what the sprite sheet itself looks like when animated.  If you want a different explosion, just press space again and you'll get a new random explosion sprite sheet.  If you want to keep what you see, press enter and the app will write the sprite sheet texture as a PNG image with a fully transparent background.

    As for the code itself... I'm not the world's best programmer, and I'm still learning XNA on the whole.  The algorithms I used are VERY inefficient which is the point of making the explosion into a sprite sheet instead of using it as a "live" particle generator.  I'm sure there are better, less intensive ways to accomplish my task, but the end result is what matters here, and I personally think the resulting animations are nice.  The code is heavily commented.  Heavily.  Way more than it probably should be, but I wanted people to be able to learn from the code so I figured more was better in this case.  There are a good deal of hard-coded values/magic numbers strewn about the code, but at the moment it does what I want it to and I when I need to reuse it I'll likely make it more flexible.  The primary values that will affect how the explosions are generated are stored in consts in #region Members.

    Feel free to take this code and do whatever you want with it.  Learn from it, modify it, reuse it, whatever you like for whatever purpose you like, I don't care.  If you feel like mentioning my name somewhere in whatever-you-do-with-it, that's fine.  If not, I'm not going to lose any sleep or chase you down or anything. :)  If you make something cool with it, I'd love to see it!  I welcome any/all comments and criticisms on the app, but please try to be constructive.

    Without any further babbling on my end, you can download the project here:
    http://www.fileden.com/files/2009/6/4/2465621/ExplosionGenerator2.1.rar

    [Edit:  Fixed a bug discovered by zygote from www.ziggyware.com having to do with the renderTarget object]
  • 6/4/2009 5:57 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    I probably should've included one of the sprite sheets generated by the software. :)

    explosion sprite sheet
  • 6/4/2009 9:33 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    VERY NICE!
    It is just nice to see people release software publicly that they created
    I think its cool that you consider yourself not to be a great programmer
    because even though the code may not be the most efficient or optimized,
    you have created a useful piece of software and that aint so easy.
    I feel the same way about anything i create,
    usually i can do hard stuff by finding cheap backdoor methods to get it done,
    its satisfying to get it done but it feels like there is always a better way.
    Anyway i think you have done a great job
  • 6/4/2009 9:37 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    Very cool... thanks for putting the work into creating/updating this and giving it back to the community.
  • 6/5/2009 4:01 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    Very nice! I'm sure I'll find a use for this.
    "Software is never finished, it is in varying states of 'less broken'" because "If it ain't broke, it doesn't have enough features yet"
    The signature that was too big for the 512 char limit
  • 6/5/2009 9:07 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    What am I doing wrong if, when I run it and hit space, nothing appears after it's done generating the spritesheet?
  • 6/5/2009 11:11 PM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    Pfhoenix:
    What am I doing wrong if, when I run it and hit space, nothing appears after it's done generating the spritesheet?


    Hmm... I'm not sure.  Are you using XGS 3.0, Visual Studio 2008, and .NET 3.5?  I imagine that this framework is pretty rock solid across systems as long as all of the components are in place.  It might be a display issue, or it could be a rendering issue (which would cause a display issue, but I digress).  After it's done generating the sprite sheet, try pressing enter to see if it stores the PNG file correctly.  This would help determine if it's not rendering properly in the first place or if it's just not displaying the spritesheet properly.  Failing that, have you modified any of the code at all?

    Has anyone else had any issues with this app?  I've ran it on two systems (XP Pro, Vista Ultimate) both running XGS 3.0, Visual STudio 2008, and .NET 3.5 and haven't had any problems.
  • 6/6/2009 1:30 AM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    I tested both at work and at home, both using GS3, .NET 3.5 SP1, quality nVidia cards. I regularly run XNA stuff on both machines. On both machines I get the same behavior - I load the solution, run debug, press space bar, watch the title change to working, and when it's done, I see nothing but the cornflowerblue background. Hitting enter gets a 1KB png output that's pure alpha of 0 (which looking at your code means 0,0,0,0).

    Why don't you do a release build and zip that up somewhere as well?
  • 6/6/2009 4:09 AM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    Pfhoenix:
    I tested both at work and at home, both using GS3, .NET 3.5 SP1, quality nVidia cards. I regularly run XNA stuff on both machines. On both machines I get the same behavior - I load the solution, run debug, press space bar, watch the title change to working, and when it's done, I see nothing but the cornflowerblue background. Hitting enter gets a 1KB png output that's pure alpha of 0 (which looking at your code means 0,0,0,0).

    Why don't you do a release build and zip that up somewhere as well?


    Weird that it doesn't work for you.  I'm curious if anyone else has had any problems with the source.  Well, regardless, here's a realease build as requested.  I've tested the EXE on two separate machines, and it does work for me.  I even included one of the images it generated.  Please let me know if the release build works or not for you?  Thanks :)

    http://www.fileden.com/files/2009/6/4/2465621/ExplosionGenerator2.0.ReleaseBuild.rar
  • 6/6/2009 4:28 AM In reply to

    Re: Explosion Generator v2.0 (Sprite Sheet Generator)

    zygote from www.ziggyware.com apparently found a problem with my renderTarget object.  His post can be found here.  I've modified my original post to point at the updated source.  If anyone has any problems with the new code, please let me know?  Thanks! :)
  • 6/8/2009 12:59 PM In reply to

    Re: Explosion Generator v2.1 (Sprite Sheet Generator)

    " I looked at this, but the main problem I had with it was that whatever background color I used to generate the explosion animation would "seep" into the final drawing of my sprites, looking especially weird when drawn over another image"

    I just want to say that if you use photoshop it is easy to remove black colour by going to channels viewer, and checking red channel as only visible, then click on the icon of channel t select pixels in the channel. Marching ants should appear in som part of image. Then select rgb channel and go back to layers mode with selection you made. Press SHIFT + CTRL + I to invert pixels, and hit DELETE...Voila...your image has no black pixels:)
  • 6/8/2009 2:56 PM In reply to

    Re: Explosion Generator v2.1 (Sprite Sheet Generator)

    northmantif:
    " I looked at this, but the main problem I had with it was that whatever background color I used to generate the explosion animation would "seep" into the final drawing of my sprites, looking especially weird when drawn over another image"

    I just want to say that if you use photoshop it is easy to remove black colour by going to channels viewer, and checking red channel as only visible, then click on the icon of channel t select pixels in the channel. Marching ants should appear in som part of image. Then select rgb channel and go back to layers mode with selection you made. Press SHIFT + CTRL + I to invert pixels, and hit DELETE...Voila...your image has no black pixels:)


    I have next-to-none Photoshopping skills so not only did I not know this is possible, but I'm not completely sure I understood what you said. ;)  With that said, I did try some things in Paint.NET but had no success there.  I'm still glad I was able to do it through code anyway - it was a good programming exercise.
  • 8/21/2009 6:30 PM In reply to

    Re: Explosion Generator v2.1 (Sprite Sheet Generator)

    VERY NICE, THANK YOU!
Page 1 of 1 (13 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG