Hey guys,
I am trying to get my collision event to be triggered by the local variable crate,but I cannot find a way.So please help me.Thank you.
Also if I create another local function and place my crate variable in there,the transition doesn’t work,I tried and it gives me an error when I try to triger the collision event using that function.
My Main.lua file :
require ("Crate") local physics = require ("physics") physics.start() physics.setGravity (0,0) local function onSpawn (event) for i = 0,0 do local crate = Crate:new() physics.addBody (crate,"static") crate.x = math.random (50,300) crate.y = 450 local removeCrate = function () display.remove (crate) crate = nil end cIntro = transition.to (crate,{time = 20000,x = 0,onComplete = removeCrate}) end end timer.performWithDelay (9000,onSpawn,0) local function onCollision (event) if event.phase == "began" then print ("It works!") end end Runtime:addEventListener ("collision",onCollision)
And here is the Crate.lua file :
Crate = {} function Crate:new() local self = display.newGroup() self:insert(display.newImage("Icon.png")) return self end
The tutorial I followed: http://lazywombat.co.uk/object-oriented-programming-in-corona-sdk-part-1-basics/