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]