Hi everybody, I'm trying to make the code below working. I have prepared a simplified, commented version just for you :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | -- vars local balls = {} local mW,mH = display.contentWidth*0.5, display.contentHeight*0.5 -- physics local physics = require "physics"; physics.start() physics.setGravity( 0, 0 ); physics.setDrawMode( "hybrid" ) -- FUNCTIONS local function placeBall( anglePerBall, ballspeed ) balls[#balls+1] = display.newCircle( mW, mH-50, 20 ) balls[#balls].yReference = 50 balls[#balls]:rotate( anglePerBall ) physics.addBody( balls[#balls], "dynamic", { isSensor = true, radius = 20 } ) balls[#balls].id = #balls balls[#balls].delta = ballspeed end local function mainLoop() for i=1,#balls do balls[i]:rotate(balls[i].delta) end end local function onGlobalCollision( event ) if ( event.phase == "began" ) then print( "Global report: " .. event.object1.id .. " & " .. event.object2.id .. " collision began" ) end -- MY PROBLEM -- print only once on terminal if "began" / never print if "ended" -- anyway don't laucnh when balls collisions ... end -- GO for i=1,2 do placeBallWithJoint( i*90, i*3 ) end Runtime:addEventListener("enterFrame", mainLoop) Runtime:addEventListener( "collision", onGlobalCollision ) |