Collison Question

Hi, I have a question regarding collisions. If i have an ball image falling from the top of screen, and when it comes in contact with another image how do i make the score updated (score=score+1)?

Im not good wit collisions please help if you know :slight_smile: Thanks!!!

With listeners. See http://docs.coronalabs.com/guide/physics/collisionDetection/index.html 

Basically, if you add a collision listener it is called when a collision occurs. It is a function (can be a method I suspect) that is called whenever two objects collide, and it tells you what they are. 

So if you write:

function myCollisionListener(event)

and add it with:

Runtime:addEventListener("collision",myCollisionListener)

it will be called on a collision - you can add names to objects so you can tell what has it what, see the docs ref above, and when your ball hits your floor, you can increment a score.

With listeners. See http://docs.coronalabs.com/guide/physics/collisionDetection/index.html 

Basically, if you add a collision listener it is called when a collision occurs. It is a function (can be a method I suspect) that is called whenever two objects collide, and it tells you what they are. 

So if you write:

function myCollisionListener(event)

and add it with:

Runtime:addEventListener("collision",myCollisionListener)

it will be called on a collision - you can add names to objects so you can tell what has it what, see the docs ref above, and when your ball hits your floor, you can increment a score.

I think what you are asking is how or when to update the score.

In your collision function you have phases.

local onCollison = function(event)

   if event.phase == “began” then

     score = score + 1

   end

end

or…

if event.phase == “ended” then

  score = score + 1

end

I think what you are asking is how or when to update the score.

In your collision function you have phases.

local onCollison = function(event)

   if event.phase == “began” then

     score = score + 1

   end

end

or…

if event.phase == “ended” then

  score = score + 1

end