Hey Dave,
I fixed the collision problem.The laser beam is a dynamic object and the cows are static objects.The cow is a sprite object declared in another file.
But how do I get the cow to trigger the collision event?
I can do this in two ways:
-
Declaring the cow as a global variable,if I choose this option how can I make my for loop to work?
-
declaring in in a local function,as a local variable,but if I choose the second option it will give me a nil value when I call the seSequence method.
Thank you!
local beam = display.newImageRect("Beam.png" ,90,200) beam.rotation = 90 beam.isVisible = false physics.addBody (beam,"dynamic") beam.gravityScale = 0 beam.isSensor = true beam:setLinearVelocity (0,0) -- This is the first method that I used. local function cows (event) local c = Cow:new() c.x = 100 c.y = math.random (0,500) physics.addBody (c,"static") end local function spawning (event) for i = 0,0 do cows() end end local function onCol (event) if event.phase == "began" then print ("works") end end timer.performWithDelay (10000,spawning,0) Runtime:addEventListener ("collision",onCol)