alestane icon

Physics contact test

alestane | PRO | 03/11/14 01:35:43 AM UTC | 0 ⭐ | 352 👁️ | Never ⏰ | []
Lua |

570 B

|

None

|

0 👍

/

0 👎

local physics = require "physics"
 
local floor = display.newRect(0, display.contentCenterY, display.contentWidth, 30)
 
local ball = display.newGroup()
ball.x, ball.y = 20, display.contentCenterY - 20
display.newCircle(ball, 0, 0, 20)
display.newRect(ball, -8, -8, 16, 16)
    :setFillColor(0x00)
 
physics.start()
 
physics.addBody(floor, 'static')
physics.addBody(ball, 'dynamic', {radius=20})
 
physics.setGravity(1, 9.8)
 
physics.setReportCollisionsInContentCoordinates(true)
 
floor:addEventListener('preCollision',
    function(event)
        print(event.x, event.y)
    end
)

Comments