\_W = display.viewableContentWidth \_H = display.viewableContentHeight local physics = require("physics") physics.start () physics.setDrawMode("hybrid") local xOfGravity local yOfGravity --local jump = false local ballinair = true local tapping = false local sheetInfo = require("ball") local ballSheet = graphics.newImageSheet( "ball.png", sheetInfo:getSheet() ) local background = display.newRect (0,0, \_W, \_H) local ground = display.newRect (0, (\_H - 80), \_W, (\_W - 80)) ground:setFillColor (255,0,0) local leftwall = display.newRect (0, 0, 80, \_H) leftwall:setFillColor (255,0,0) local rightwall = display.newRect ((\_W - 80), 0 , 80, \_H) rightwall:setFillColor (255,0,0) local ball = display.newImage (ballSheet, sheetInfo:getFrameIndex("ball")) ball.x = 400 ball.y = 400 physics.addBody(ground, "static",{friction = 0.5, bounce = 0.1}) physics.addBody(leftwall, "static",{friction = 0.5, bounce = 0.2}) physics.addBody(rightwall, "static",{friction = 0.5, bounce = 0.2}) physics.addBody(ball, {friction = 0.5, bounce = 0.1}) -- function accelerometer:accelerometer(event.xGravity) -- xOfGravity = event.xGravity -- ball.x = (xOfGravity/2) + ball.x --end function onCollision(q) print ("rg") if (q.phase == "began") then print ("collision") if (q.object1.myName == "ball" and q.object2.myName == "ground") then ballinair = false if (tapping == true and ballinair == false) then ballinair = true ball:setLinearVelocity( 0, -200 ) --jump end print ("touching ground") elseif (q.object1.myName == "ball" and q.object2.myName == "leftwall") then if (q.object1.myName == "ball" and q.object2.myName == "ground") then ballinair = false else ballinair = true end elseif (q.object1.myName == "ball" and q.object2.myName == "rightwall") then if (q.object1.myName == "ball" and q.object2.myName == "ground") then ballinair = false else ballinair = true end end end end function tap (q) tapping = true print ("gg") end Runtime:addEventListener("tap", tap) Runtime:addEventListener( "collision", onCollision ) --Runtime:addEventListener("accelerometer", accelerometer)
What is wrong, guys? The tap isn’t detected.