One by one addEventListener collision

I’m working on a simple breakout game and I’ve problem with

ball:addEventListener( “collision”, removeBricks )

, it works fine until the ball hits two bricks at same time, than the up/down direction (vy) switch twice, making the ball continue moving up or down.

How can do one by one addEventListener collision and disable multiple collides at once?

    function removeBricks(event)

    

        if event.other.isBrick == 1 then

            vy = vy * (-1)    

            …

        end

    end

You can simply try another if check to work around that problem.

[LUA]

function removeBricks(event)

   local other = event.other

   if other.isBrick == 1 then

      if vy < 0 and other.y < self.y then

         vy = vy * (-1)

      elseif vy > 0 and other.y > self.y then

         vy = vy * (-1)

      end

     

      other:removeSelf() – or wathever you want to do with the block

   end

end

[/LUA]

You can simply try another if check to work around that problem.

[LUA]

function removeBricks(event)

   local other = event.other

   if other.isBrick == 1 then

      if vy < 0 and other.y < self.y then

         vy = vy * (-1)

      elseif vy > 0 and other.y > self.y then

         vy = vy * (-1)

      end

     

      other:removeSelf() – or wathever you want to do with the block

   end

end

[/LUA]