Collision help please

Hi,

I have 4 groups of enemies created with a for loop.

I assign a collision listener to each group.

How can I listen for all the enemies together in one collision function? I currently have four.

My enemies are:

enemy

enemyPurple

enemyRed

enemyYellow

Utimatley all enemies will have the same collision code i.e. display.remove(enemy), enemy =nil

Any help with the function would be tremendous help, collisions do get the better of me even after reading the docs.

Thank you

[lua]

frontgroup = display.newGroup()

    local posXfront = { 60, 80, 100, 120, 140, 160, 180, 200, 220, 240 }
    local posYfront = { 80, 95, 110 }

    enemy = {}
    local b = 1

    for y = 1, 3 do
        for x = 1, 10 do
            enemy[b] = display.newRect(0, 0, 15, 10)
            physics.addBody(enemy[b], { isSensor = true, filter = filtersModule.enemyFilter })
            enemy[b].isVisible = true
            enemy[b].isBodyActive = true
            enemy[b].myName = “enemy”
            --enemy[b].collision = onCollision
            enemy[b]:addEventListener(“collision”, enemy)
            frontgroup:insert(enemy[b])
            enemy[b].x, enemy[b].y = posXfront[x], posYfront[y]
            b = b + 1
        end

    end

     function enemy:collision (event)
         local phase = event.phase
         if phase == “ended” then
           print("… blue collision enemy")
             end
        end

[\lua]

Did you want to detect collisions between individual groups AND the entire “enemy” group? If so, you can use specific identifiers within one collision function. It’s been useful to me. Try this:

function onCollision (self, event) local phase = event.phase if phase == "ended" and self.id == "blueEnemy" then print("...... blue collision enemy") end end

If you just want to identify a collision between player and enemy regardless of enemy identification, just take out the self.id part. Are you encountering an issue/error at any point?

No errors, I was wondering if there was a better way.

I am having issues with the physics registering correctly.

When I start the enemies moving the collisions register incorrectly , well they register on the wrong enemy.

Somebody said it was because i need to move each enemy no the group but I dont understand it.

I tried moving the enemies with delta time, moving the group and other ways…I got all to work but the collisions were the same unless I stopped the movement and everything was ok…

check the picture, ignore the upper block it was moving

http://s21.postimg.org/t3xx74sg7/Capture.png

That picture is truly worth a thousand words. Here’s a link to a tutorial describing how to create a brickbreaker game like you are attempting to code. It has some useful tips. I haven’t gone through it to vouch for it’s efficacy.

http://mobile.tutsplus.com/tutorials/corona/corona-sdk_brick-breaker/

Here’s a youtube tut on the same thing, but again, I haven’t run through it, and the post date is a good 2 years in the past:

http://www.youtube.com/watch?v=4ee261iYTaI

Did you want to detect collisions between individual groups AND the entire “enemy” group? If so, you can use specific identifiers within one collision function. It’s been useful to me. Try this:

function onCollision (self, event) local phase = event.phase if phase == "ended" and self.id == "blueEnemy" then print("...... blue collision enemy") end end

If you just want to identify a collision between player and enemy regardless of enemy identification, just take out the self.id part. Are you encountering an issue/error at any point?

No errors, I was wondering if there was a better way.

I am having issues with the physics registering correctly.

When I start the enemies moving the collisions register incorrectly , well they register on the wrong enemy.

Somebody said it was because i need to move each enemy no the group but I dont understand it.

I tried moving the enemies with delta time, moving the group and other ways…I got all to work but the collisions were the same unless I stopped the movement and everything was ok…

check the picture, ignore the upper block it was moving

http://s21.postimg.org/t3xx74sg7/Capture.png

That picture is truly worth a thousand words. Here’s a link to a tutorial describing how to create a brickbreaker game like you are attempting to code. It has some useful tips. I haven’t gone through it to vouch for it’s efficacy.

http://mobile.tutsplus.com/tutorials/corona/corona-sdk_brick-breaker/

Here’s a youtube tut on the same thing, but again, I haven’t run through it, and the post date is a good 2 years in the past:

http://www.youtube.com/watch?v=4ee261iYTaI