... You could attach a smoke emitter to a missile to create a trail effect ....
You know what, I spent about 8 hours streight trying to get that to work ...
and kept getting killed by the same error:
somehow, when I try to add a Particle to the ParticleEngine (through the component system - it seems to work outsude that) I get an exaption that i thonk is trying to tell me that my Main class is null

which I'm pretty sure is not the case, what with everything working...
I've had powercuts on and off all day today, so no progress. Going to make short post/edits incase it goes again.
I'll edit this post in a while with a stack trace and my particle code. If anyone can shead any light on this I would be much releived!
It was starting to drive me a little bit mad. (er)

EDIT:
[code=Stack Trace]
run:
DRGame constructor - line 77.
Particle Engine Instanceated - line 98.
Load method begun - line 114.
Exception in thread "main" java.lang.NullPointerException
at SpaceLib.Components.ParticleEmitterComponent.<init>(ParticleEmitterComponent.java:32)
at SpaceLib.Objects.Projectile.<init>(Projectile.java:38)
at SpaceLib.Components.WeaponComponent.initProjectile(WeaponComponent.java:102)
at SpaceLib.Components.WeaponComponent.<init>(WeaponComponent.java:48)
at SpaceLib.Ship.Ship.<init>(Ship.java:42)
at GameLib.DRGame.Load(DRGame.java:130)
at GameLib.DRGame.<init>(DRGame.java:105)
at isogameengine_01.Main.main(Main.java:21)
[/code]
[code=ParticleEmitterComponent]public class ParticleEmitterComponent extends Component{
ParticleEffect myEffect;
public ParticleEmitterComponent(int id, Entity parent)
{
super(id, parent);
this.myEffect = new ParticleEffect();
Main.getGame().GetParticleEngine().AddEffect(myEffect);
}
@Override
public void Update(int deltaTime)
{
this.myEffect.Position = this.Parent().GetPhysicsComponent().getPosition();
}
}
[/code]
[code=Projectile]public class Projectile extends Entity{
private Entity source;
private double speed;
private int projectileAge;
private int projectileLife;
private Vector2D destination;
public Projectile(Entity source, Vector2D d)
{
this.source = source;
this.destination = d;
this.SetComponent(new PhysicsComponent(0, this));
this.SetComponent(new RenderableComponent(0, this));
this.SetComponent(new TrailComponent(0, this));
this.SetComponent(new ParticleEmitterComponent(0, this));
initVars();
Fire();
}
private void initVars()
{
this.speed = 800;
this.projectileAge = 0;
this.projectileLife = 1000;
this.GetRenderableComponent().GetSprite().load("artAssets\\projectiles\\cannonShell2.png");
}
public void Fire()
{
Vector2D go = Vector2D.Sub(this.physicsComponent.getPosition(), destination);
double theta = go.getAngle();
this.physicsComponent.setPosition(this.source.GetPhysicsComponent().getPosition());
this.physicsComponent.setVelocity(Vector2D.fromAngle(this.physicsComponent.getPosition(),
speed,
theta));
//this.physicsComponent.setVelocity(new Vector2D(0,10));
}
private void Detonate()
{
/*
if(this.GetParticleComponent() != null)
{
this.GetParticleComponent().AddEffect(this.GetPhysicsComponent().getPosition(),
Main.getEffects().Explosion1);
}
else
{
this.SetComponent(new ParticleComponent(0, this.parent));
this.GetParticleComponent().AddEffect(this.GetPhysicsComponent().getPosition(), "Explosion1");
}
this.GetRenderableComponent().GetSprite().load("artAssets\\effects\\particles\\explosion1.png");
*
*/
}
private void Expire()
{
this.Detonate();
}
public void Update(int deltaTime)
{
/*this.projectileAge += deltaTime;
if(this.projectileAge > this.projectileLife)
{
//this.Expire();
//this.parent.getChildren().remove(this);
}
*/
if(this.physicsComponent != null)
this.physicsComponent.Update(deltaTime);
if(this.renderableComponent != null)
this.renderableComponent.Update(deltaTime);
if(this.statsComponent != null)
this.statsComponent.Update(deltaTime);
if(this.navigatorComponent != null)
this.navigatorComponent.Update(deltaTime);
if(this.trailComponent != null)
this.trailComponent.Update(deltaTime);
if(this.particleEmitterComponent != null)
this.particleEmitterComponent.Update(deltaTime);
if(this.children != null)
for(Entity e: this.children)
{
if(e != null)
e.Update(deltaTime);
}
}
/*
@Override
public void Render(Graphics2D g)
{
this.GetRenderableComponent().Render(g);
//g.drawRect((int)this.GetPhysicsComponent().getPosition().getX(),
// (int)this.GetPhysicsComponent().getPosition().getX(), 2, 2);
}
*/
}
[/code]
[code=WeaponsComponent]public class WeaponComponent extends Component{
int cooldownTime; // cooldown between bursts (ms)
int burstTime; // time between shots (ms)
int burstCount; // number of shots to fire per burst
int timer; // miliseconds since last state-change.
boolean firing = false;
Entity target;
float acuracyOffset;
Vector2D offset;
Projectile projectileTemplate;
public WeaponComponent(int i, Entity p)
{
super(i,p);
this.cooldownTime = 500;
this.burstTime = 0;
this.burstCount = 1;
this.offset = new Vector2D();
this.acuracyOffset = 0.05f;
initProjectile();
}
public void SetTarget(Entity e)
{
this.target = e;
}
public void Fire()
{
if(this.target != null)
firing = true;
}
public void CeaseFire()
{
firing = false;
}
@Override
public void Update(int deltaTime)
{
if(firing)
{
//System.out.println("Weapon Timer: " + this.timer);
if(this.timer < this.cooldownTime)
{
timer += deltaTime;
}
else if(this.timer >= this.cooldownTime)
{
Vector2D V2T = Vector2D.Sub(this.Parent().GetPhysicsComponent().getPosition(),
this.target.GetPhysicsComponent().getPosition());
double D2T = V2T.getLengh();
double A2T = V2T.getAngle();
Random rand = new Random();
double defl = (rand.nextDouble() - rand.nextDouble()) * this.acuracyOffset;
Projectile x = new Projectile(this.Parent(), Vector2D.fromAngle(
this.Parent().GetPhysicsComponent().getPosition(),
D2T, A2T+defl));
Main.getGame().GetWorldProjectiles().AddProjectile(x);
timer = 0;
}
}
}
private void initProjectile()
{
this.projectileTemplate = new Projectile(this.Parent(), new Vector2D());
//this.projectileTemplate.GetRenderableComponent().GetSprite().load(
// "artAssets\\projectiles\\cannonShell1.png");
}
}
[/code]
I'm afraid that its all rather hacked together and got really messed up yesterday as I was trying random crap to try fix it. I think I need to have a good clean-up of the code I have before going any further.