Collision
Collision uses the sprite collision box, set in the sprite editor. Two instances collide when their boxes overlap. Instances with no sprite do not collide, and angle is ignored.
React to contact
Section titled “React to contact”Register in onSpawn.
| Function | What it does |
|---|---|
onCollide(object, fn) |
Calls fn(other) on every step with contact. |
onTouchStart(object, fn) |
Calls fn(other) once, when the contact starts. |
onTouchEnd(object, fn) |
Calls fn(other) once, when the contact ends. |
function onSpawn(self) self:onTouchStart("Coin", function(moeda) moeda:destroy() self.moedas = self.moedas + 1 end)endvoid onSpawn() override { onTouchStart<Coin>([this](Coin& moeda) { moeda.destroy(); moedas++; });}| Function | What it does |
|---|---|
touching(object) |
The instance of the object touching now, or nothing. |
collidesAt(object, x, y) |
true if there would be contact with this instance at (x, y). |
findAt(object, x, y) |
The instance that would be touching at that position, or nothing. |
placeFree(x, y) |
true if no solid blocks that position. |
collisionBox() |
The collision box in the world: x, y, width and height. |
if self:touching("Espinho") then restart() end
if self:placeFree(self.x + 2, self.y) then self.x = self.x + 2 endif (touching("Espinho")) restart();
if (placeFree(x + 2, y)) x += 2;maskreplaces the collision box with that of another sprite;flipXmirrors the box together with the drawing.onCollideruns after the movement of the step. An instance that spawns touching firesonTouchStarton the first step.- C++: the functions accept the class (
onCollide<Coin>,collidesAt<Wall>(x, y)) or the name in quotes; with the name, the callback receivesEntity&. - To move and stop at walls, use
moveAndStop: Movement.
