Explosions

helloo,

I guess i’m not the first one who tries to make nice looking explosions! :stuck_out_tongue: (not super complex particles and geometry effects, just something like a flat sprite)
so i’m wondering if nobody here has already the stuff for making nice explosions that is “ready to use”! ::slight_smile:

Try this out :
http://www.binarysun.co.uk/products/exgen.htm

The only problem with the tool (or most tools of that genre) is that you need to unleash your Photoshop/Paintshop mad skills to generate half-decent translucent images out of the baked-on-black sprites. That’s the hard part, and I found you can never truly recreate the crisp original look.

Unless your game has a black backdrop with no need for translucency. Right. ::slight_smile:

(this subject isn’t all that J3D-specific tho, might be moved in the general discussion forum or something)

HTH,
BK

Code-wise it is Java3D related.

What do you think about the FlyingGuns explosions??

Quite simply done, but very performance sensitive!

…hmm… i took a look at it but they look like more than i need, they are textured particles flying around. In my case, i would however prefer a “sprite based” explosion. (I’m picky heh?! :P).
But i think i can inspire myself from the source to make such a sprite based explosion… i’ll give it a try.
…thanks!

ok, here it is: a plane showing a sprite. It’s very simplistic, uncommented, without transparency and fancy features, but it works.


import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.image.BufferedImage;
import java.util.Enumeration;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class Sprite extends BranchGroup
{
      private ImageComponent2D[] images;
        private Texture2D texture;

        private int initialLoopCount;
        private int loopCount;
        private int imageIndex = 0;

      private SpriteAnimation anim;

      public Sprite(ImageComponent2D[] images, long totalTime, int loopCount)
      {
            this.images = images;
            this.loopCount = loopCount;
            initialLoopCount = loopCount;

            // prepare the textured appearance
            texture = new Texture2D(Texture2D.BASE_LEVEL, Texture2D.RGB, 64, 64);
            texture.setCapability(Texture.ALLOW_IMAGE_WRITE);
            texture.setImage(0, images[0]);
            Appearance app = new Appearance();
            app.setTexture(texture);

            // build the plane which will show the images
            QuadArray plane = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);

                  // set plane corner coordinates
                  Point3f p = new Point3f();
                  p.set(-1.0f, 1.0f, 0.0f);
                  plane.setCoordinate(0, p);
                  p.set(-1.0f, -1.0f, 0.0f);
                  plane.setCoordinate(1, p);
                  p.set( 1.0f, -1.0f, 0.0f);
                  plane.setCoordinate(2, p);
                  p.set( 1.0f, 1.0f, 0.0f);
                  plane.setCoordinate(3, p);

                  // set texture coordinates
                  TexCoord2f q = new TexCoord2f();
                  q.set(0.0f, 1.0f);
                  plane.setTextureCoordinate(0, 0, q);
                  q.set(0.0f, 0.0f);
                  plane.setTextureCoordinate(0, 1, q);
                  q.set(1.0f, 0.0f);
                  plane.setTextureCoordinate(0, 2, q);
                  q.set(1.0f, 1.0f);
                  plane.setTextureCoordinate(0, 3, q);

            // add it
            this.addChild(new Shape3D(plane, app));

            // adds the image updater to animate the sprite
            anim = new SpriteAnimation(totalTime / images.length);
            anim.setSchedulingBounds(this.getBounds());
            this.addChild(anim);
      }

      public void reset()
      {
            loopCount = initialLoopCount;
            imageIndex = 0;
            anim.setEnable(true);
      }

      public void stop()
      {
            anim.setEnable(false);
      }


      /**
       * This behavior changes the texture image at given time intervals
       */
      private class SpriteAnimation extends Behavior
      {
            private WakeupCriterion wakeupCondition;

            SpriteAnimation (long delay)
            {
                  wakeupCondition = new WakeupOnElapsedTime(delay);
            }

            public void initialize()
            {
                  this.wakeupOn(wakeupCondition);
            }

            public void processStimulus(Enumeration criteria)
            {
                  texture.setImage(0, images[imageIndex]);

                  imageIndex++;

                  if (imageIndex == images.length)
                  {
                        imageIndex = 0;
                        if (loopCount > 0)
                              loopCount--;
                        if (loopCount == 0)
                              this.setEnable(false);
                  }
                  this.wakeupOn(wakeupCondition);
            }
      }

      public static void main(String[] args) throws Exception
      {
            SimpleUniverse u = new SimpleUniverse();
            u.getViewingPlatform().setNominalViewingTransform();

            TextureLoader loader;
            ImageComponent2D[] images = new ImageComponent2D[12];
            for (int i=1; i<=12; i++)
            {
                  loader = new TextureLoader("explosion" + i + ".png", null);
                  images[i-1] = loader.getImage();
            }

            Sprite sprite = new Sprite(images, 1000, -1);
            u.addBranchGraph(sprite);
      }
}

Are you sure that isn’t a true performance killer?

it looks like ok.
I tested this class with an image update per 10ms (a lot!!!). Then, i placed the line you mentionned into comments and tested again.
I got about 725 fps without image updating, whereas i got 685 with image updating (every 10 ms!).

Another way for the sprite animation is to make a
number of images on one texture that are spaced out. Like
a film real. then change the texture cords moving the
texture across the sprite. loads faster and better on
memory.

even another solution would be to make X textured planes and place them under a switch. Then just select the displayed child one aftre another.