Collisions
Register the reaction in onSpawn. The collision box comes from the sprite, set in the sprite editor.
function onSpawn(self) self:onTouchStart("Player", function(player) player.moedas = player.moedas + 1 self:destroy() end)endvoid onSpawn() override { onTouchStart<Player>([this](Player& player) { player.moedas++; destroy(); });}onTouchStartruns once, when the contact starts;onCollide, on every step in contact;onTouchEnd, when it ends.
Test a position
Section titled “Test a position”if not self:collidesAt("Wall", self.x + 2, self.y) then self.x = self.x + 2end
local inimigo = self:findAt("Enemy", self.x, self.y + 1)if inimigo then inimigo:destroy() endif (!collidesAt<Wall>(x + 2, y)) x += 2;
if (Enemy* inimigo = findAt<Enemy>(x, y + 1)) inimigo->destroy();Check Solid on the object (or paint solid tiles). moveAndStop stops at them and placeFree(x, y) tells whether the position is free.
