Sure, sorry.
Spawning the Player:
function spawnPlayer() player = display.newImage("playership2.png", 50, 50) physics.addBody(player, "static", {density = 1, friction = 0, bounce = 0}) player.x = display.contentWidth \* 0.5 player.y = display.contentHeight - player.height player.name = "player" player.alive = true player:toFront() end
Spawning Enemies:
function spawnEnemy() Runtime:addEventListener("collision", onCollision) enemyNumber = enemyNumber + 1 enemies:toFront() enemyGroup[enemyNumber] = display.newImage("enemyship1.png", 50, 50) enemyGroup[enemyNumber].alive = true physics.addBody (enemyGroup[enemyNumber], "dynamic", {density=0.5, friction=0.3, bounce=0}) enemyGroup[enemyNumber].myName = "enemy" end
Collision Function:
function onCollision(event) if(event.object1.myName == "player" and event.object2.myName == "enemy") or (event.object1.myName == "enemy" and event.object2.myName == "player") then --code end