Skip to content
Download

Collisions

Register the reaction in onSpawn. The collision box comes from the sprite, set in the sprite editor.

objects/Coin.lua
function onSpawn(self)
self:onTouchStart("Player", function(player)
player.moedas = player.moedas + 1
self:destroy()
end)
end
  • onTouchStart runs once, when the contact starts; onCollide, on every step in contact; onTouchEnd, when it ends.
if not self:collidesAt("Wall", self.x + 2, self.y) then
self.x = self.x + 2
end
local inimigo = self:findAt("Enemy", self.x, self.y + 1)
if inimigo then inimigo:destroy() end

Check Solid on the object (or paint solid tiles). moveAndStop stops at them and placeFree(x, y) tells whether the position is free.

Reference: Collision, Movement.