Sign in to follow this  

collision not working on corona sdks

This topic is 822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
 
 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this