[SOLVED] Explosion not visibly exploding

When the enemy node is detected as have been removed from the main enemy node (like after being shot), I remove the enemy from the main enemy node and trigger an explosion (using the palette explosion code). When the explosion has 0 particles, I finally remove the enemy instance from an enemy List.

I’ve tested the code using println(), and everything seems to be functioning correctly (the ParticleEmitter even registered as having particles), except there are no visible particles.

I know that my ParticleEmitter is attached to the rootNode through a few other nodes (main enemy node and environment node).

protected void explode(AssetManager assetManager) {
	debrisEffect = new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10);
	Material debrisMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
	debrisMat.setTexture("Texture", assetManager.loadTexture("Textures/Effects/fiery.png"));
	debrisEffect.setMaterial(debrisMat);
	debrisEffect.setImagesX(3); debrisEffect.setImagesY(3); // 3x3 texture animation
	debrisEffect.setRotateSpeed(4);
	debrisEffect.setSelectRandomImage(true);
	debrisEffect.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 4, 0));
	debrisEffect.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f));
	debrisEffect.setGravity(0f,6f,0f);
	debrisEffect.getParticleInfluencer().setVelocityVariation(.60f);
	exploNode.attachChild(debrisEffect);
	debrisEffect.emitAllParticles();
	debrisEffect.setParticlesPerSec(0);
	exploId = id+" explosion";
	exploNode.setName(exploId);
	exploded = true;
	System.out.println("explode!!!");
}

How do you know that?

The included code doesn’t show. It only shows a magic “explodeNode”… which for all we know could be attached to the removed enemy node.

This is in the Enemy class. It handles explosion triggering and cleanup.

protected boolean isReal(Node enemyNode) {
	// detects removal from Node badguys
	return enemyNode.getChild(id) != null;
}
protected void doExplosion(AssetManager manager, Node enemyNode) {
	if (!isReal(enemyNode) && !exploded) {
		explode(manager);
		enemyNode.attachChild(exploNode);
	}
}
protected void cleanExplosion(Node enemyNode) {
	//if (exploded) System.out.println(debrisEffect.getParticles().length);
	if (exploded && debrisEffect.getParticles().length == 0) {
		enemyNode.detachChildNamed(exploId);
		remove = true;
	}
}

This code is in the simpleUpdate method.

ArrayList<Badguy> removables = new ArrayList<>();
//System.out.println(badguyList.size());
for (Badguy i : enemyList) {
	i.setMove(enviro);
	i.move();
	i.doExplosion(assetManager, enemyNode);
	i.cleanExplosion(enemyNode);
	if (i.purge()) removables.add(i);
}
if (!removables.isEmpty()) for (Badguy i : removables) {
	enemyList.remove(i);
}

EnemyNode is directly attached to the rootNode, and is never removed from it. The magical exploNode is attached to enemyNode (which is constant). And yes, I know for a fact that exploNode is attached to enemyNode.

Edit: Sorry, when I said “Enemy class” I meant “Badguy class”

Maybe try posting this code that is only relevent to the ParticleEmitter into a quick new BasicGame template with the blue cube, and see if it renders properly there.

At first glance, your code for the particle emitter looks correct. The only thing to make sure of is that your custom texture named “fiery” is indeed a 3x3 texture atlas.

Edit: I also notice you aren’t setting a startSize or an endSize. I’m not sure if you scale up your particleEmitter elsewhere by scaling the parent node - but i think it could also be possible that your particle emitters are too small to be noticed depending on the scale of the rest of your world, since its all relative.

Or as Paul mentioned, it could be a node attachment issue.

I fixed it. I wasn’t translating my explosion to the correct place. :roll_eyes:

1 Like