Ok so my collision is prob not set up correctly so its not working correctly… here the video and the code…
Sorry for the bad voice, everyone is sleeping…
and the code
local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) function scene:create( event ) local sceneGroup = self.view local BackGround = display.newImageRect( sceneGroup, "BackGround.png", 1080, 1920) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("ItsAGo") elseif ( phase == "did" ) then print("ItsAGo2") local P = 1 local floor = display.newImageRect(sceneGroup, "floor.png", 351, 32) floor.x = display.contentWidth \* 0.5 floor.y = 510 physics.addBody( floor, "static", {density = .01, friction = 0.5, bounce = 0 } ) local circle = {} local spawnCircles = function () local FallDown = math.random(display.contentWidth \* 0.2, display.contentWidth \* 0.8 ) circle[P] = display.newImageRect( sceneGroup, "circle.png", 31, 31 ) circle[P].x = FallDown circle[P].y = -70 physics.addBody( circle[P], "dynamic", {density = .01, friction = 0.5, bounce = 0 }) circle[P].gravityScale = 0.1 physics.setGravity( 0, 10 ) circle[P].value = P P = P + 1 if P == 5 then P = 1 end-- I've chosen to reset the counter at 5, if you need more than 5 circles on screen then increase this end myTimer = timer.performWithDelay( 2000, spawnCircles, -1) --1000 is the time function onCollision(event) if( event.phase ~= "began" ) then return true end display.remove(circle[P]) return true end Runtime:addEventListener("collision", onCollision) end end -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene
Thanks!