tModLoader Projectile Afterimage Effect?

mundyy

Terrarian
hello all, i am trying to make a projectile have an aftereffect shadow, such as the flying dragon, phantom phoenix, terrarian bolt projectiles etc but i cant seem to find any answers or code relating to generating this effect, both online and in the source code (projectile file), so help would be greatly appreciated ^_^
thanks in advance!
 
You can make another projectile with the similar sprite, which is the after image with no damage and infinite pierce
Then you can make it slowly fade away by increasing the Projectile.alpha in the AI

In your main projectile, you can spawn in the after image with
int newProj = Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Projectile.velocity/2, Mod.Find<ModProjectile>("[your projectile name]").Type, Projectile.damage, Projectile.knockBack, Projectile.owner);
 
In case someone is still looking, here's some code that causes afterimage trails (have not tested in 1.4 yet):

public override void SetStaticDefaults()
{
ProjectileID.Sets.TrailCacheLength[projectile.type] = 7; // how long you want the trail to be
ProjectileID.Sets.TrailingMode[projectile.type] = 0; // recording mode
}

public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) {
//Redraw the projectile with the color not influenced by light
Vector2 drawOrigin = new Vector2(Main.projectileTexture[projectile.type].Width * 0.5f, projectile.height * 0.5f);
for (int k = 0; k < projectile.oldPos.Length; k++) {
Vector2 drawPos = projectile.oldPos[k] - Main.screenPosition + drawOrigin + new Vector2(0f, projectile.gfxOffY);
Color color = projectile.GetAlpha(lightColor) * ((float)(projectile.oldPos.Length - k) / (float)projectile.oldPos.Length);
spriteBatch.Draw(Main.projectileTexture[projectile.type], drawPos, null, color, projectile.rotation, drawOrigin, projectile.scale, SpriteEffects.None, 0f);
}
return true;
}

The code in PreDraw is what allows the lines in SetStaticDefaults() to take effect. Just having the SetStaticDefaults() lines alone isn't enough, and won't produce any afterimages.
 
Back
Top Bottom