I have the function onCollision sometimes at the second “if” when the bottle touches the object “inside” which is a simple rectangle on phase “began” the level increases for 2 is this a bug?
function onCollision(event) if (event.phase == "began") then local obj1 = event.object1 local obj2 = event.object2 if (obj1.myName == "bottle") and ( obj2.myName == "inside" ) or (obj2.myName == "bottle") and ( obj1.myName == "inside" ) then transition.to(bottle,{bodyType = "static",time=0,x = math.random(140,230),y=0 ,rotation= math.random( -40,40 )}) audio.play( insidew ) if (barrelTime \> 1000) then barrelTime = barrelTime - 33 end level = level + 1 elseif (obj1.myName == "bottle") and ( obj2.myName == "barrel" ) or (obj2.myName == "bottle") and ( obj1.myName == "barrel" ) then audio.play( barrelSound ) elseif(obj1.myName == "bottle") and ( obj2.myName == "outside" ) or (obj2.myName == "bottle") and ( obj1.myName == "outside" ) then audio.play( outside ) gameOver = "Game Over!".." \nYour score is :".. maxscore overText = display.newText(uiGroup, gameOver, display.contentCenterX, 150, native.systemFont, 40 ) overText:setFillColor( 0, 0, 0 ) timer.performWithDelay( 1000, transition.cancel("barrelmovement")) timer.performWithDelay( 2000, endGame ) end levelText.text = level maxscore = level end end Runtime:addEventListener("collision", onCollision)
I use the outline graphics for the bottle and rectangle for the “inside”