Hey,
When my app loads I am spawning a player and an opponent. Whenever the player collides with the opponent I want to create a new opponent. The first and second opponent are created but there is no collision-detection on the second opponent. What am I doing wrong?
local function onCollision( event ) if ( event.phase == "began" and event.other.type == "opp" ) then spawnOpp() elseif ( event.phase == "ended") then
display.remove( event.other ) event.other = nil
end end player:addEventListener( "collision", onCollision ) spawnOpp = function () local opp = display.newRect( w/2, h, w, padding/2 ) physics.addBody( opp, "dynamic", {density = 0, bounce=0} ) opp.y = startHeight opp.type = "opp" opp:setFillColor(unpack(color.white)) opp.isSensor = true opp.isVisible = true opp.gravityScale = 0 end spawnOpp()