So I want to have a function respond to a object.
floor = display.newImage(“floor.png”)
floor.y = display.contentHeight - floor.stageHeight/2
floor.name = “spikes”
physics.addBody(floor, “static”, { friction = 1.0 })
local function spawnCrate()
local balloon = display.newImage(“red.png”);
balloon.x = math.random(600);
balloon.y = -100;
physics.addBody( balloon, { density=2.0, friction=0.5, bounce=0.3 } )
balloon:addEventListener(“touch”, removeBody)
balloon.name = “balloon”
end
timer.performWithDelay(500,spawnCrate,50)
As you can see, I have balloons spawning hence the spawn word I just used crate as that was the orignal idea, so how would having the floor interact with the balloon work? I am using oncollision aswell
local onCollision = function (self, event)
if event.phase == “began” then
if event.other.name == “spikes” then
local gameoverText = display.newText(“Game Over!”, 0, 0, “HelveticaNeue”, 35)
gameoverText:setTextColor(255, 255, 255)
gameoverText.x = display.contentCenterX
gameoverText.y = display.contentCenterY
gameoverText:addEventListener(“collision”, onCollision)
self:removeSelf()
self = nil
end
end
end [import]uid: 39840 topic_id: 9459 reply_id: 309459[/import]
