When swords clash so hard that sparks fly, then you know there are heroes at work. Let's create some sparks and make them dash in random directions!
Make a copy of
Main.java
and name the classParticle2Sparks.java
. Remember to also refactor the first line of themain()
method toParticle2Sparks app = new Particle2Sparks();
.Copy the included file
assets/Effects/spark.png
into your project'sassets/Effect
directory. It includes a sprite animation of sparks.In the
simpleInitApp()
method, create a spark emitter and attach it to the scene:public void simpleInitApp() { ParticleEmitter sparksEmitter = new ParticleEmitter("Spark emitter", Type.Triangle, 60); rootNode.attachChild(sparksEmitter);
Create a material, load the spark texture, and set the material:
Material sparkMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); sparkMat.setTexture("Texture", assetManager.loadTexture("Effects/spark.png")); sparksEmitter.setMaterial(sparkMat);
You see that the...