0
votes

When I compile this is showing

error: Cannot translate an object before collision is resolved

and when I'm building app for android it shows me an error#5 (null).

Here's my code:

function onLocalCollision(meteor, event)
  if event.phase == "began" then
  if event.object1.myName == "meteor" and
     event.object2.myName == "rocket" then
    score = score - 1
    scoreNumber.text = score
    restart.isVisible = true
    meteor.x = 500   
    meteor.y = 300
    meteor2.x = 500
    meteor2.y = 200
    meteor3.x = 500
    meteor3.y = 100
    event.object2.alpha = 0.2
    rocket:applyForce(-150,0,rocket.x,rocket.y)
    lives = lives -1
    livesNumber.text = lives
    if lives < 1 then
    lives = 3
    score = 0
    scoreNumber.isVisible = false
    livesText.isVisible = false
    livesNumber.isVisible=false
    hearticon.isVisible = false
    scoreText.isVisible = false
    gameover.isVisible = true
    restart.x = 100000
    end
  end
  end
end


meteor.collision = onLocalCollision
Runtime:addEventListener("collision", meteor)
1

1 Answers

0
votes

The problem with your code is that you cannot translate during a collision (function) so if you just say:timer.performWithDelay(100, function() rocket:applyForce(-150,0,rocket.x,rocket.y) end, 1) it should resolve your problem and/or just create a callback function.

"Modifying Objects The objects involved in the collision should not be removed or any of it's properties altered during a collision event. You should use timer.performWithDelay() if they want to modify object position values or other properties within the collision events.

Removing the object or modifying the properties in the collision event could cause the simulator to crash."

http://docs.coronalabs.com/api/event/collision/index.html