collision not working on corona sdks

Started by
0 comments, last by JTippetts 8 years, 7 months ago

my code collision is not working

local physics = require("physics")

physics.start()
display.setDefault("background", 88/255)
local myRect = display.newRect(100,100,100,100)
myRect.anchorX = 1
myRect.anchorY = 1
myRect.x = display.contentCenterX
myRect.y = display.contentCenterY
physics.addBody( myRect,{ density=4.0, friction=1, bounce=0.4})
local coolRect = display.newRect(20,20,500,50)
coolRect.anchorY = 1
coolRect.anchorY = 1
coolRect.x = 250
coolRect.y = 525
physics.addBody( coolRect,{ isSensor = false} )
coolRect.bodyType = "kinematic"
local widget = require( "widget" )
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
transition.moveTo(myRect, { x=100 + 115, y=100 + 115, time=500 } )
end
end
local button1 = widget.newButton
{
width = 240,
height = 120,
defaultFile = "Play.png",
overFile = "Play.png",
label = "button",
onEvent = handleButtonEvent
}
local function onCollision( event )
if ( event.phase == "began" ) then
print( "began: " .. event.object1.myRect .. " & " .. event.object2.coolRect )
elseif ( event.phase == "ended" ) then
print( "ended: " .. event.object1.myRect .. " & " .. event.object2.coolRect )
end
end
Advertisement
What do you expect to happen? What actually happens? What other things have you tried?

If you just dump a pile of code and say "it's not working", you probably won't get much of a response. You have to provide more information.

This topic is closed to new replies.

Advertisement