Jump to content
  • Advertisement
Sign in to follow this  
Tejwinder

collision not working on corona sdks

This topic is 1190 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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!