Move an object
axis returns -1 to 1 for a pair of actions. Multiply by the speed, in pixels per step.
function onUpdate(self) self.x = self.x + axis("esquerda", "direita") * 2 self.y = self.y + axis("cima", "baixo") * 2endvoid onUpdate() override { x += axis("esquerda", "direita") * 2; y += axis("cima", "baixo") * 2;}Stop at walls
Section titled “Stop at walls”Check Solid on the wall object and move with moveAndStop.
function onUpdate(self) local dx = axis("esquerda", "direita") * 2 local dy = axis("cima", "baixo") * 2 self:moveAndStop(dx, dy)endvoid onUpdate() override { const float dx = axis("esquerda", "direita") * 2; const float dy = axis("cima", "baixo") * 2; moveAndStop(dx, dy);}Same speed on diagonals
Section titled “Same speed on diagonals”if dx ~= 0 and dy ~= 0 then dx = dx * 0.7071 dy = dy * 0.7071endif (dx != 0 && dy != 0) { dx *= 0.7071f; dy *= 0.7071f;}