No problem, try this. It might have some lines of extra useless code but it works and you’ll understand how to do it. If you need more help feel free to ask
local spawnTrue = true;
display.setStatusBar( display.HiddenStatusBar )
local physics = require "physics"
physics.start()
physics.setDrawMode ( "normal" )
--physics.setDrawMode ( "normal" )
physics.setGravity( 0, 0 )
local leftwall = display.newRect(0, 0, 1, display.contentHeight )
local rightwall = display.newRect( display.contentWidth, 0, 1, display.contentHeight )
local ceiling = display.newRect( 0, 0, display.contentWidth, 1 )
ceiling.myName = "ceiling"
physics.addBody(leftwall, "static", { bounce = 0.1 } )
physics.addBody(rightwall, "static", { bounce = 0.1 } )
physics.addBody(ceiling, "static", { bounce = 0.1 } )
local ground = display.newRect( 0, 0, 320, 50)
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 540
local groundShape = { -240,-20, 240,-20, 240,20, -240,20 }
physics.addBody( ground, "static", { friction=1.0, density=1.0, bounce=0 } )
balloon = {}
local i = 1
local randomPos = math.random ( 0, 320 )
local function moveShit(event)
local fattie = event.target
fattie:applyLinearImpulse( 0, -5, event.x, event.y )
end
local function spawnStuff( event )
if spawnTrue == true then
balloon[i] = display.newCircle( math.random( 0, 320), 320, 15 )
balloon[i]:setFillColor( 0, 0, 255 )
balloon[i].x = math.random( 0, 320 )
balloon[i].y = 230
balloon[i].myName = "balloon"
physics.addBody(balloon[i] , "dynamic", { radius = 17 })
balloon[i]:addEventListener( "touch", moveShit )
i = i + 1
end
end
spawnBalls = timer.performWithDelay( 1500, spawnStuff, 0 )
local function moveShit(event)
local fattie = event.target
fattie:applyLinearImpulse( 0, -5, event.x, event.y )
end
local testNum = 0;
local function onCollideObject(event)
if ( event.phase == "began" ) then
if event.object1.myName == "ceiling" and event.object2.myName == "balloon" then
timer.performWithDelay( 3000, delayTest, 1 )
function delayTest()
event.object2:removeSelf()
event.object2 = nil
end
end
end
end
Runtime:addEventListener( "collision", onCollideObject)
The parts you are most interested is in spawnStuff and then you already saw the collide code. Click on the balls to make them hit the wall btw
EDIT: Meh its currently off by one, Ill try to fix it later gotta go now [import]uid: 77199 topic_id: 25028 reply_id: 101883[/import]