Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Making a simple game in Love 2D framework where if I click on an object then it disappears.

Do I check to see if I've clicked the enemy inside a function in the enemy object? Or just in my main.lua? Currently I have this code in my main.lua:

function love.mousepressed(x, y, button)
   if button == "l" then
      for i,b in ipairs(bugs) do
         if b:isClicked(x, y) then
            table.remove(bugs, i)
         end
      end
   end
end

Is there a standard design pattern on where this code should belong?

share|improve this question
add comment

1 Answer

What I do is make each entity handle its own collisions in its update function. This may or may not be practical depending on your project...But for me, it works and makes it easier to manage collisions when there's multiple instances of an object.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.