hey guys so I had a look at the API reference page and fallowed the instructions there but i am not able to make the crates move so what am i doing wrong?
here is the script:
local physics = require “physics”
physics.start ()
system.activate( “multitouch” )
physics.setGravity()
gx, gy = physics.setGravity( 0, 9 )
local function dragBody ( event )
local body = event.target
local phase = event.phase
local stage = display.getCurrentStage ()
if “began” == phase then
stage:setFocus ( body, event.id )
body.isFocus = true
body.tempJoint = physics.newJoint ( “touch”, body, event.x, evebt.y )
elseif body.isFocus then
if “moved” == phase then
body.tempJoint:setTarget ( event.x, event.y )
elseif “ended” == phase or “cabcelled” == phase then
stage:setFocus ( body, nil )
body.isFocus = false
body.tempJoint:removeSelf ()
end
end
return true
end
local ground = display.newImage( “ground.png” )
ground.x = display.contentWidth / 2
ground.y = 445
ground.myName = “ground”
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
local function spawnCrate()
local crate1 = display.newImage( “Bcu.png” )
crate1.x = math.random( 320 )
crate1.y = -50
local crate2 = display.newImage( “Bcu.png” )
crate2.x = math.random( 320 )
crate2.y = -30
local crate3 = display.newImage( “Jcu.png” )
crate3.x = math.random( 320 )
crate3.y = -60
local crate4 = display.newImage( “Rcu.png” )
crate4.x = math.random( 320 )
crate4.y = -60
local crate5 = display.newImage( “Pcu.png” )
crate5.x = math.random( 320 )
crate5.y = -60
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate3, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate4, { density=3.0, friction=0.5, bounce=0.3 } )
physics.addBody( crate5, { density=3.0, friction=0.5, bounce=0.3 } )
end
timer.performWithDelay( 500, spawnCrate, 30 )
crate:addEventListener ( “touch”, dragBody ) [import]uid: 10351 topic_id: 3406 reply_id: 303406[/import]