How do you spawn multipart enemies?

Hi all,

after a year of life, I’ve finally found some time to revisit my shmup.

Whilst for the most part, every ‘enemy’ is individually coded, there are parts of my game where I intend to use random-spawning, to add a little edge and prevent repetitiveness.

The code I’m using to do this, is contained within a function and looks something like this:

function createEnemy() numEnemy = numEnemy +1 print(numEnemy) --enemies:toFront() enemyArray[numEnemy] = display.newSprite( imgSheet , sequenceData ) enemyArray[numEnemy]:setSequence("rotate") enemyArray[numEnemy]:play() physics.addBody ( enemyArray[numEnemy] , {density=0.0, friction=0, bounce=0}) enemyArray[numEnemy].isFixedRotation=true enemyArray[numEnemy] .myName = "enemy" startlocationX = display.contentWidth +200 enemyArray[numEnemy] .x = startlocationX startlocationY = math.random (0, display.contentHeight) enemyArray[numEnemy] .y = startlocationY transition.to ( enemyArray[numEnemy] , { time = math.random (1000, 2000), x=display.contentWidth-200, y=MyShip.y, onComplete=charge } ) group:insert(enemyArray[numEnemy] ) end

Now, what I’d like to do, instead of using sprite sheets for the explosion, is attach a particle emitter and listener to each enemy and I’m having a problem, attaching.

I’ve decided to go with Particle Candy (yes, I know) because I like the way it looks, but I can only attach a single (the same) emitter to each enemy as it’s spawned, I don’t seem to be able to ‘spawn’ a concurrent emitter.

…In order to attach my emitter (how I’m doing it now), I’m including this code at the end of the block above:

Particles.CreateFXField("Field50", 2, enemyArray[numEnemy] .x,enemyArray[numEnemy] .y , 2.5, 40, true, 18)

‘Field 50’, just means that I’ve already used 49 for another purposes.

I then attach the field using another function, like this:

Particles.GetFXField("Field50").x = enemyArray[numEnemy] .x Particles.GetFXField("Field50").y = enemyArray[numEnemy] .y

So, like I said, I’m only using a single emitter which changes to the next ‘spawnee’ when it’s born.

I would like to assign a piece of code that spawns a different emitter to each enemy. Stuck :frowning:

M

Gotta bump this one, still stuck. Anyone?

If I were you, I would seriously consider moving to CBEffects for your particles. It is current, has several demos, is easy to customize, and allows for multiple “vents”. You could easily assign one vent per enemy. That said, I have never used Particle Candy and perhaps there is some API I am unaware of that would resolve your issue. Perhaps another developer, one who has used particle candy, can add their two cents.

Hey, thanks for the advice… The thing is, the ‘challenge’ isn’t just ‘particle’ specific. I’m just looking for a way to spawn assets, that become children of objects in another table… Possibly. LOL. I dunno.

Gotta bump this one, still stuck. Anyone?

If I were you, I would seriously consider moving to CBEffects for your particles. It is current, has several demos, is easy to customize, and allows for multiple “vents”. You could easily assign one vent per enemy. That said, I have never used Particle Candy and perhaps there is some API I am unaware of that would resolve your issue. Perhaps another developer, one who has used particle candy, can add their two cents.

Hey, thanks for the advice… The thing is, the ‘challenge’ isn’t just ‘particle’ specific. I’m just looking for a way to spawn assets, that become children of objects in another table… Possibly. LOL. I dunno.