Particle Candy Q - Trying to set my emitter to remain on multiple instances of my bullet object. -- video --

Video
(HD quality when downloaded… Dropbox’s preview window doesn’t show the full res -_- )

Just to clarify -
At the end when I mention something about the “completion of the animation” I meant, when the animation/effect is triggered it will would still complete the animation cycle even if the emitter had, as I say, “defaulted to the most recently triggered event.”

Thoughts, comments and advice are all greatly appreciated. :slight_smile:

-Saer

Could you create a stable of emitters, say 3-5 of them, and apply them in order of each bullet created?  You could keep each emitter attached to a bullet until the bullet hits, then return that emitter back to the ‘pool’ of unused emitters.  That way you can have multiple bullets in the air at once each streaming their own trail.  In the unlikely event you have so many bullets in the air you run out of emitters you could either not attach an emitter to the last bullet, or attach the first used emitter to the last bullet.  With so many bullets in the air it’s unlikely anyone would notice the oldest bullet’s trail running out too early.

Hmmm… that’s a possible solution. However, I’d like my enemy-tank bullets to have the same effect… so in levels where there are a quite a few enemies I’d have to create a large number of emitters to keep up with all the projectiles. 

Like I mentioned in the video, my explosion emitter works even when there are multiple objects calling it.
Is there a way I can have every instance of the bullet (whether it’s a bullet emanating from the player tank or from an enemy tank) utilizing the same emitter?  Unless I’m missing something, my explosion emitter is setup the same as my bullet emitter - other than having different particles attached to it.

Maybe the folks from X-Pressive could offer their thoughts?
 

You can’t have the same emitter in two places at once.  I’m guessing your explosions are quick effects that emit particles over a frame or two so if the emitter jumps around from explosion to explosion you won’t notice, but for a trail effect that takes a second or more to move you’ll definitely notice.  When you create your emitters set their visible property to true and you’ll see the emitter used for your explosions jump around.  If you use one emitter for all trails then you’ll see that emitter jump every time a new trail is started even if the old one hasn’t finished yet.  

The particle type effect is separate from the emitter.  So you can create one particle type (smoke trail) and apply it to each emitter that is assigned to each bullet.  You can even assign different, and multiple, particle types to the same emitter.

You do have to keep in mind and manage the performance issues of having many, many emitters each spewing many particles every frame.  The idea of a fixed number of emitters in a “stable” can help you manage that. The number of emitters as well as the particle types themselves can be tuned to get the performance you desire.    

Ahh, okay.
After re-watching my video I did in fact notice the emitter was at the location of the second explosion (I was getting a different emitter icon mixed up with the explosion one.)

Though what still confuses me is that when I shoot a tank and the explosion starts, the animation/effect finishes its cycle (the lifetime of the particles range from one to three seconds) even when I shoot a second tank and cause the emitter to go to that object.
Naturally I thought the bullet should behave the same way, but when I (just for the heck of it) make the bullet trail/effect last three seconds it is immediately stopped when I fire a second bullet - again 'causing the emitter to assign itself to the new bullet…

Anyways, I’ll try what you suggested.

-Saer

P.S. I assume when you say “stable” you mean table?

I think what is confusing you is the difference between the time an emitter emits vs. the lifetime of a particle once emitted.  The explosion emitter might emit particles for only a frame or two, but once emitted those particles could have a lifetime of several seconds.  In the mean time you can reuse that emitter in another location for a different explosion even as the first explosion’s particles are still playing out their lifetimes.  As long as you don’t have two explosions _starting _on the exact same frame (assuming the emission is only for a single frame) then you won’t have a problem.

But if in your game’s design you will have simultaneous or overlapping emission, you will see truncated effects, or even lose an effect entirely if two start at exactly the same frame.   That is what is happening with your current trail effect. In that case, again, you could have a few emitters dedicated to your trails and cycle through them for each next effect.

I actually did mean “stable”, as in a stable of horses ready to be used.  You create/init the emitters up front before you need them and they’re ready to be called on if necessary.  In a scene with only a couple slowly reloading tanks you might be able to get away with only one or two emitters in your stable, but in a particularly heavy scene with 10 tanks each shooting rapidly at each other you might need more.   It all depends on your game’s design (bullet speed, reloading speed, number of tanks, etc.)

And just as a head’s up, with particles it’s especially important to test on an actual device, preferably something on the low end of what you want to support.  Corona’s desktop simulator can handle many times more particles before the framerate starts to drop than a crummy Nook Color or 3 year old off brand Android phone will.   Good luck!

Okay, that makes sense. Thanks for clarifying. :slight_smile:

lol good metaphor. :wink:
As far as the design goes, I’ll me adding delays and putting a cap on how many bullets an enemy can fire at one time - so they won’t be firing as fast and as frequent like in the video.

In reference to creating a stable of emitters, would the following be valid:

 

local BulletEmitters = {} local CreateBulletEmitter = function() Particles.CreateEmitter("PBEmitter", 0, 0, 0, true, true) PBEmitter = Particles.GetEmitter("PBEmitter") Particles.CreateParticleType ("BulletSTrail", { -- Particle code -- }) Particles.AttachParticleType("PBEmitter" , "BulletSTrail", 32, 99999,0) return PBEmitter end

then do something like:

for i = 1,10 do BulletEmitters[#BulletEmitters+1] = CreateBulletEmitter() Particles.SetEmitterTarget( "PBEmitter", PTbullet, true, 0, 0, 0 ) end

Right after my user_bullet function is called I could have it run through the code and for every bullet that is fired, create a new emitter and attach it to the bullet. Does that make sense at all lol?

I’m not sure if that would be the proper way to format it, regardless it’s just an example of my thinking process.

Thanks for your suggestion and advice. If the method I mentioned will not work, I’ll just go with what you suggested.

-Saer

It’s been a while since I’ve messed with my particle code, but I’m pretty sure the name for each emitter needs to be unique.  In your function above they would all be named “PBEmitter” which I think will cause you lots of headaches.  

For example, where I set up emitters I just initialize a bunch off the bat like so:

    -- CREATE AN EMITTER (NAME, SCREENW, SCREENH, ROTATION, ISVISIBLE, LOOP)     Particles.CreateEmitter("E1", 0, 0, 180, false, false)--     Particles.CreateEmitter("E2", 0, 0, 0, false, false)--for UI     Particles.CreateEmitter("E3", 0, 0, 0, false, false)--for jumper center     Particles.CreateEmitter("E4", 0, 0, 0, false, false)--for UI     Particles.CreateEmitter("E5", 0, 0, 0, false, false)--for jumper head     Particles.CreateEmitter("E6", 0, 0, 0, false, false)--for jumper footL     Particles.CreateEmitter("E7", 0, 0, 0, false, false)--for jumper footR     Particles.CreateEmitter("E8", 0, 0, 0, false, false)--for playfield objects  

As you can see they all have different names.  I use them for different game objects, but in your case you could use a similar naming convention to easily cycle through and grab a fresh emitter each time you need a particle effect.  You would have a function grab the next unused emitter, apply a particle type to it, perhaps change the emission rate etc., then return it so you can position it where you need to.  Hope that makes sense.

Hmm… yeah, I can see how that could potentially be an issue :\

That seems like it could become quite cumbersome, but I guess if that’s the best way I’ll just have to make do. :slight_smile:
Luckily I can use this - EmitterIsActive(“emitterName”) - to check if an emitter is active, which will make it easier to decide whether or not an emitter should be in the ‘stable’ or not.

I’m not 100% sure on how this will need to be formatted, but I think I’ve got a pretty good idea.

Thanks again. :slight_smile:

-Saer

P.S. Btw, thanks for the heads up regarding particles run on the simulator vs. realtime testing on a device. I am actually planning on purchasing my Apple Dev license this weekend, so I can start running/testing my game on a device. :smiley:

Could you create a stable of emitters, say 3-5 of them, and apply them in order of each bullet created?  You could keep each emitter attached to a bullet until the bullet hits, then return that emitter back to the ‘pool’ of unused emitters.  That way you can have multiple bullets in the air at once each streaming their own trail.  In the unlikely event you have so many bullets in the air you run out of emitters you could either not attach an emitter to the last bullet, or attach the first used emitter to the last bullet.  With so many bullets in the air it’s unlikely anyone would notice the oldest bullet’s trail running out too early.

Hmmm… that’s a possible solution. However, I’d like my enemy-tank bullets to have the same effect… so in levels where there are a quite a few enemies I’d have to create a large number of emitters to keep up with all the projectiles. 

Like I mentioned in the video, my explosion emitter works even when there are multiple objects calling it.
Is there a way I can have every instance of the bullet (whether it’s a bullet emanating from the player tank or from an enemy tank) utilizing the same emitter?  Unless I’m missing something, my explosion emitter is setup the same as my bullet emitter - other than having different particles attached to it.

Maybe the folks from X-Pressive could offer their thoughts?
 

You can’t have the same emitter in two places at once.  I’m guessing your explosions are quick effects that emit particles over a frame or two so if the emitter jumps around from explosion to explosion you won’t notice, but for a trail effect that takes a second or more to move you’ll definitely notice.  When you create your emitters set their visible property to true and you’ll see the emitter used for your explosions jump around.  If you use one emitter for all trails then you’ll see that emitter jump every time a new trail is started even if the old one hasn’t finished yet.  

The particle type effect is separate from the emitter.  So you can create one particle type (smoke trail) and apply it to each emitter that is assigned to each bullet.  You can even assign different, and multiple, particle types to the same emitter.

You do have to keep in mind and manage the performance issues of having many, many emitters each spewing many particles every frame.  The idea of a fixed number of emitters in a “stable” can help you manage that. The number of emitters as well as the particle types themselves can be tuned to get the performance you desire.    

Ahh, okay.
After re-watching my video I did in fact notice the emitter was at the location of the second explosion (I was getting a different emitter icon mixed up with the explosion one.)

Though what still confuses me is that when I shoot a tank and the explosion starts, the animation/effect finishes its cycle (the lifetime of the particles range from one to three seconds) even when I shoot a second tank and cause the emitter to go to that object.
Naturally I thought the bullet should behave the same way, but when I (just for the heck of it) make the bullet trail/effect last three seconds it is immediately stopped when I fire a second bullet - again 'causing the emitter to assign itself to the new bullet…

Anyways, I’ll try what you suggested.

-Saer

P.S. I assume when you say “stable” you mean table?

I think what is confusing you is the difference between the time an emitter emits vs. the lifetime of a particle once emitted.  The explosion emitter might emit particles for only a frame or two, but once emitted those particles could have a lifetime of several seconds.  In the mean time you can reuse that emitter in another location for a different explosion even as the first explosion’s particles are still playing out their lifetimes.  As long as you don’t have two explosions _starting _on the exact same frame (assuming the emission is only for a single frame) then you won’t have a problem.

But if in your game’s design you will have simultaneous or overlapping emission, you will see truncated effects, or even lose an effect entirely if two start at exactly the same frame.   That is what is happening with your current trail effect. In that case, again, you could have a few emitters dedicated to your trails and cycle through them for each next effect.

I actually did mean “stable”, as in a stable of horses ready to be used.  You create/init the emitters up front before you need them and they’re ready to be called on if necessary.  In a scene with only a couple slowly reloading tanks you might be able to get away with only one or two emitters in your stable, but in a particularly heavy scene with 10 tanks each shooting rapidly at each other you might need more.   It all depends on your game’s design (bullet speed, reloading speed, number of tanks, etc.)

And just as a head’s up, with particles it’s especially important to test on an actual device, preferably something on the low end of what you want to support.  Corona’s desktop simulator can handle many times more particles before the framerate starts to drop than a crummy Nook Color or 3 year old off brand Android phone will.   Good luck!

Okay, that makes sense. Thanks for clarifying. :slight_smile:

lol good metaphor. :wink:
As far as the design goes, I’ll me adding delays and putting a cap on how many bullets an enemy can fire at one time - so they won’t be firing as fast and as frequent like in the video.

In reference to creating a stable of emitters, would the following be valid:

 

local BulletEmitters = {} local CreateBulletEmitter = function() Particles.CreateEmitter("PBEmitter", 0, 0, 0, true, true) PBEmitter = Particles.GetEmitter("PBEmitter") Particles.CreateParticleType ("BulletSTrail", { -- Particle code -- }) Particles.AttachParticleType("PBEmitter" , "BulletSTrail", 32, 99999,0) return PBEmitter end

then do something like:

for i = 1,10 do BulletEmitters[#BulletEmitters+1] = CreateBulletEmitter() Particles.SetEmitterTarget( "PBEmitter", PTbullet, true, 0, 0, 0 ) end

Right after my user_bullet function is called I could have it run through the code and for every bullet that is fired, create a new emitter and attach it to the bullet. Does that make sense at all lol?

I’m not sure if that would be the proper way to format it, regardless it’s just an example of my thinking process.

Thanks for your suggestion and advice. If the method I mentioned will not work, I’ll just go with what you suggested.

-Saer

It’s been a while since I’ve messed with my particle code, but I’m pretty sure the name for each emitter needs to be unique.  In your function above they would all be named “PBEmitter” which I think will cause you lots of headaches.  

For example, where I set up emitters I just initialize a bunch off the bat like so:

    -- CREATE AN EMITTER (NAME, SCREENW, SCREENH, ROTATION, ISVISIBLE, LOOP)     Particles.CreateEmitter("E1", 0, 0, 180, false, false)--     Particles.CreateEmitter("E2", 0, 0, 0, false, false)--for UI     Particles.CreateEmitter("E3", 0, 0, 0, false, false)--for jumper center     Particles.CreateEmitter("E4", 0, 0, 0, false, false)--for UI     Particles.CreateEmitter("E5", 0, 0, 0, false, false)--for jumper head     Particles.CreateEmitter("E6", 0, 0, 0, false, false)--for jumper footL     Particles.CreateEmitter("E7", 0, 0, 0, false, false)--for jumper footR     Particles.CreateEmitter("E8", 0, 0, 0, false, false)--for playfield objects  

As you can see they all have different names.  I use them for different game objects, but in your case you could use a similar naming convention to easily cycle through and grab a fresh emitter each time you need a particle effect.  You would have a function grab the next unused emitter, apply a particle type to it, perhaps change the emission rate etc., then return it so you can position it where you need to.  Hope that makes sense.

Hmm… yeah, I can see how that could potentially be an issue :\

That seems like it could become quite cumbersome, but I guess if that’s the best way I’ll just have to make do. :slight_smile:
Luckily I can use this - EmitterIsActive(“emitterName”) - to check if an emitter is active, which will make it easier to decide whether or not an emitter should be in the ‘stable’ or not.

I’m not 100% sure on how this will need to be formatted, but I think I’ve got a pretty good idea.

Thanks again. :slight_smile:

-Saer

P.S. Btw, thanks for the heads up regarding particles run on the simulator vs. realtime testing on a device. I am actually planning on purchasing my Apple Dev license this weekend, so I can start running/testing my game on a device. :smiley:

Hey,

I had to work on some other stuff, so I just recently had time to work on this. :]
 

I’m very close to it working, but I’ve got a minor problem…
First, here is my code:
[lua]
local function shootBullet()
    
    PlayerBulletCount = PlayerBulletCount + 1
    print(“PlayerBulletCount increased by 1”)
    
    local pt = mathapi.rotateAboutPoint( {x=user_turret.x,y=user_turret.y-60}, user_turret, user_turret.rotation - 90 )
    PTbullet = loader:createSpriteFromSHDocument(“Weapon5ex”, “GameFX”, “LevelAssets.pshs”);
    PTbullet.x = pt.x; PTbullet.y = pt.y;
    physics.addBody( PTbullet , “dynamic”, { friction= 0, bounce= 1.0, density= .6, radius= 7, filter = bulletCollisionFilter} );
    PTbullet:scale(.6,.6);
    
    PTbullet.class = “bullet”
    PTbullet.isBullet = true
    
    PTbullet.rotation = user_turret.rotation + 90
    PTbullet:applyForce( pt.x - user_turret.x, pt.y - user_turret.y, user_turret.x, user_turret.y )
    
    
    local function createBulletEmitters()
       
        local bodyName   = “E”   … (#BEmitters + 1) – This will concatenate the current number of enemy tanks to the end of the string, resulting in E1 for the first, E2 for the second, etc.
     
        local Emitter = display.newGroup()
    
        Particles.CreateEmitter(bodyName, 0, 0, 0, true, true) – Uses the base name (generated dynamically with each tank)
        Emitter.body = Particles.GetEmitter(bodyName)
        
        Particles.CreateParticleType (“BulletSTrail”,
            {
            imagePath           = “gfx/smoke01.png”,
            imageWidth            = 12,    
            imageHeight            = 12,    
            directionVariation    = 45,
            velocityVariation    = 50,
            rotationVariation    = 360,
            rotationChange        = 30,
            useEmitterRotation    = false,
            alphaStart            = 0.5,
            fadeInSpeed            = 1.5,
            fadeOutSpeed        = .5,
            fadeOutDelay        = 100,
            scaleStart            = 0.5,
            scaleVariation        = 0.5,
            scaleInSpeed        = 1.0,
            emissionShape        = 1,
            emissionRadius        = 1,
            killOutsideScreen    = true,
            lifeTime            = 200,
            blendMode            = “subtract”,
            } )
    
        Particles.AttachParticleType(bodyName , “BulletSTrail”,  32, 99999,0)
    
        local R = 153
        local G = 153
        local B = 153
        Particles.SetParticleProperty(“BulletSTrail”, “colorStart”, {R,G,B})
            
     
        if BEmitters then
            
            print( "Number of Emitters: " … tostring( #BEmitters ) )

            if #BEmitters~=0 then
    
                Particles.SetEmitterTarget( bodyName, PTbullet, true, 0, 0, 0 )
                Particles.StartEmitter(bodyName)

            end
        end
    
      Emitter:insert( Emitter.body )
     
      camera:add(Emitter, 6, false)
      
      table.insert(BEmitters, Emitter) – This adds the tank to the enemyTanks table and increments the #enemyTanks by one
      
      Emitter.body._index = table.indexOf(BEmitters, Emitter)

      return Emitter
   
    end

    for i=1,5 do
        BEmitters[#BEmitters + 1] = createBulletEmitters()
    end
    timer.performWithDelay(10, createBulletEmitters)
    
    bullets:insert( PTbullet )    
    PTbullet.collision = onBulletCollision
    PTbullet:addEventListener( “collision”, PTbullet )
    
end
[/lua]

I know these lines are most likely the cause of my troubles:
[lua]
 if #BEmitters~=0 then
    
        Particles.SetEmitterTarget( bodyName, PTbullet, true, 0, 0, 0 )
        Particles.StartEmitter(bodyName)
end
[/lua]

Obviously it would set every single emitter’s target as the bullet, which is seen when I fire a bullet - all emitters work, but they all get attached to the bullet.

Two questions:

     1. How do I attatch just one emitter to the bullet?
     2. How would I return an emitter back to the table once the bullet has collided and been removed?

Cheers!

-Saer

Edit: Sorry if the code looks weird; parts of it weren’t rendering correctly. (I am an extreme perfectionist when it comes to ‘tabbing’ my code and making it readable… hopefully it actually is readable 'n such :wink:

Edit: actually, I think I’ve solved the issue with multiple emitters being attached to one bullet -
I changed this:

    for i=1,5 do         BEmitters[#BEmitters + 1] = createBulletEmitters()     end

to this:

    for i=1,1 do         BEmitters[#BEmitters + 1] = createBulletEmitters()     end  

I still can’t figure out how to remove the emitter though.
I’m guessing I don’t need to “return” an emitter since each time a bullet is fired one is created…

Happy to report that I’ve got it working! :smiley:
I had to reformat my overall ‘shootBullet’ function.

If anyone is interested, this is the final product - I’ll be cleaning it up a bit, but nevertheless here it is:
[lua]
local function shootBullet()
 
  PlayerBulletCount = PlayerBulletCount + 1
  print(“PlayerBulletCount increased by 1”)
    
  local pt = mathapi.rotateAboutPoint( {x=user_turret.x,y=user_turret.y-60}, user_turret, user_turret.rotation - 90 )
 
 
  local emitterName   = “E”   … (#BEmitters + 1) – This will concatenate the current number of enemy tanks to the end of the string, resulting in E1 for the first, E2 for the second, etc.
     
  local Emitter = display.newGroup()
  local bullet = display.newGroup()
    
  --bullet attributes    
  bullet.body = loader:createSpriteFromSHDocument(“Weapon5ex”, “GameFX”, “LevelAssets.pshs”);
  bullet.body.x = pt.x; bullet.body.y = pt.y;
  physics.addBody( bullet.body , “dynamic”, { friction= 0, bounce= 1.0, density= .6, radius= 7, filter = bulletCollisionFilter} );
  bullet.body:scale(.6,.6);
    
  bullet.body.class = “bullet”
  bullet.body.isBullet = true
    
  bullet.body.rotation = user_turret.rotation + 90
  bullet.body:applyForce( pt.x - user_turret.x, pt.y - user_turret.y, user_turret.x, user_turret.y )

  bullet.body.class = “EnemyTank”
 
  – Bullet Emitter
  Particles.CreateEmitter(emitterName, 0, 0, 0, true, true) – Uses the base name (generated dynamically with each tank)
  bullet.emitter = Particles.GetEmitter(emitterName)
        
    Particles.CreateParticleType (“BulletSTrail”,
        {
        imagePath           = “gfx/smoke01.png”,
        imageWidth            = 12,    
        imageHeight            = 12,    
        directionVariation    = 45,
        velocityVariation    = 50,
        rotationVariation    = 360,
        rotationChange        = 30,
        useEmitterRotation    = false,
        alphaStart            = 0.5,
        fadeInSpeed            = 1.5,
        fadeOutSpeed        = .5,
        fadeOutDelay        = 100,
        scaleStart            = 0.5,
        scaleVariation        = 0.5,
        scaleInSpeed        = 1.0,
        emissionShape        = 1,
        emissionRadius        = 1,
        killOutsideScreen    = true,
        lifeTime            = 200,
        blendMode            = “subtract”,
        } )
    
    Particles.AttachParticleType(emitterName , “BulletSTrail”,  32, 99999,0)
    
    local R = 153
    local G = 153
    local B = 153
    Particles.SetParticleProperty(“BulletSTrail”, “colorStart”, {R,G,B})

    local function attachBEmitters()
     
        if BEmitters then
            
            print( "Number of Emitters: " … tostring( #BEmitters ) )

            if #BEmitters~=0 then
    
                Particles.SetEmitterTarget( emitterName, bullet.body, true, 0, 0, 0 )
                Particles.StartEmitter(emitterName)

            end
        end

      return Emitter
   
    end

    for i=1,1 do
        BEmitters[#BEmitters + 1] = attachBEmitters()
    end
    timer.performWithDelay(10, attachBEmitters)

   local onPlayerBulletCollision = function(self, event)
       
    local parentObject = PlayerBullets[self._index]       
 
        if event.phase == “began” then
        Particles.StopEmitter(“PBEmitter”)
        Particles.StopEmitter(“ETBEmitter”)
        Particles.StopEmitter(emitterName)
        display.remove(bullet.emitter)
        --table.remove(BEmitters)
         print(“bullet hit something”)
            --[[
            if event.other.class == “Player” or event.other.class == “Uturret”
            then
                print(" Hit PlayerTank “)
                bullet1:removeSelf()
                print(” Projectile Removed ")
                removePlayer()
        end–]]   

            if event.other.class == “bullet”  
            then
                display.remove(self)
                print(" two bullets collided … bullets removed “)
            end
                
        elseif  event.phase == “ended”  then
            
            print(“PlayerBulletCount decreased by 1”)
            PlayerBulletCount = PlayerBulletCount - 1
            
            print(“EnemyBulletCount increased by 1”)
            EnemyBulletCount = EnemyBulletCount - 1
            
            display.remove(self)
            print(” Projectile Removed ")
    
        
        end

    return true
    
  end
  bullet.body.collision = onPlayerBulletCollision
  bullet.body:addEventListener(“collision”, bullet.body)
 
 
  bullet:insert( bullet.body )
  --bullet:insert( bullet.emitter )
  camera:add(bullet, 6, false)
 
  table.insert(PlayerBullets, bullet) – This adds the tank to the PlayerBullets table and increments the #PlayerBullets by one
 
  bullet.body._index = table.indexOf(PlayerBullets, bullet)
  bullet.emitter._index = bullet.body._index

  return bullet
 
end

[/lua]

Cheers!

-Saer

Hey,

I had to work on some other stuff, so I just recently had time to work on this. :]
 

I’m very close to it working, but I’ve got a minor problem…
First, here is my code:
[lua]
local function shootBullet()
    
    PlayerBulletCount = PlayerBulletCount + 1
    print(“PlayerBulletCount increased by 1”)
    
    local pt = mathapi.rotateAboutPoint( {x=user_turret.x,y=user_turret.y-60}, user_turret, user_turret.rotation - 90 )
    PTbullet = loader:createSpriteFromSHDocument(“Weapon5ex”, “GameFX”, “LevelAssets.pshs”);
    PTbullet.x = pt.x; PTbullet.y = pt.y;
    physics.addBody( PTbullet , “dynamic”, { friction= 0, bounce= 1.0, density= .6, radius= 7, filter = bulletCollisionFilter} );
    PTbullet:scale(.6,.6);
    
    PTbullet.class = “bullet”
    PTbullet.isBullet = true
    
    PTbullet.rotation = user_turret.rotation + 90
    PTbullet:applyForce( pt.x - user_turret.x, pt.y - user_turret.y, user_turret.x, user_turret.y )
    
    
    local function createBulletEmitters()
       
        local bodyName   = “E”   … (#BEmitters + 1) – This will concatenate the current number of enemy tanks to the end of the string, resulting in E1 for the first, E2 for the second, etc.
     
        local Emitter = display.newGroup()
    
        Particles.CreateEmitter(bodyName, 0, 0, 0, true, true) – Uses the base name (generated dynamically with each tank)
        Emitter.body = Particles.GetEmitter(bodyName)
        
        Particles.CreateParticleType (“BulletSTrail”,
            {
            imagePath           = “gfx/smoke01.png”,
            imageWidth            = 12,    
            imageHeight            = 12,    
            directionVariation    = 45,
            velocityVariation    = 50,
            rotationVariation    = 360,
            rotationChange        = 30,
            useEmitterRotation    = false,
            alphaStart            = 0.5,
            fadeInSpeed            = 1.5,
            fadeOutSpeed        = .5,
            fadeOutDelay        = 100,
            scaleStart            = 0.5,
            scaleVariation        = 0.5,
            scaleInSpeed        = 1.0,
            emissionShape        = 1,
            emissionRadius        = 1,
            killOutsideScreen    = true,
            lifeTime            = 200,
            blendMode            = “subtract”,
            } )
    
        Particles.AttachParticleType(bodyName , “BulletSTrail”,  32, 99999,0)
    
        local R = 153
        local G = 153
        local B = 153
        Particles.SetParticleProperty(“BulletSTrail”, “colorStart”, {R,G,B})
            
     
        if BEmitters then
            
            print( "Number of Emitters: " … tostring( #BEmitters ) )

            if #BEmitters~=0 then
    
                Particles.SetEmitterTarget( bodyName, PTbullet, true, 0, 0, 0 )
                Particles.StartEmitter(bodyName)

            end
        end
    
      Emitter:insert( Emitter.body )
     
      camera:add(Emitter, 6, false)
      
      table.insert(BEmitters, Emitter) – This adds the tank to the enemyTanks table and increments the #enemyTanks by one
      
      Emitter.body._index = table.indexOf(BEmitters, Emitter)

      return Emitter
   
    end

    for i=1,5 do
        BEmitters[#BEmitters + 1] = createBulletEmitters()
    end
    timer.performWithDelay(10, createBulletEmitters)
    
    bullets:insert( PTbullet )    
    PTbullet.collision = onBulletCollision
    PTbullet:addEventListener( “collision”, PTbullet )
    
end
[/lua]

I know these lines are most likely the cause of my troubles:
[lua]
 if #BEmitters~=0 then
    
        Particles.SetEmitterTarget( bodyName, PTbullet, true, 0, 0, 0 )
        Particles.StartEmitter(bodyName)
end
[/lua]

Obviously it would set every single emitter’s target as the bullet, which is seen when I fire a bullet - all emitters work, but they all get attached to the bullet.

Two questions:

     1. How do I attatch just one emitter to the bullet?
     2. How would I return an emitter back to the table once the bullet has collided and been removed?

Cheers!

-Saer

Edit: Sorry if the code looks weird; parts of it weren’t rendering correctly. (I am an extreme perfectionist when it comes to ‘tabbing’ my code and making it readable… hopefully it actually is readable 'n such :wink:

Edit: actually, I think I’ve solved the issue with multiple emitters being attached to one bullet -
I changed this:

    for i=1,5 do         BEmitters[#BEmitters + 1] = createBulletEmitters()     end

to this:

    for i=1,1 do         BEmitters[#BEmitters + 1] = createBulletEmitters()     end  

I still can’t figure out how to remove the emitter though.
I’m guessing I don’t need to “return” an emitter since each time a bullet is fired one is created…