Skip to content
Download

Movement

Every step the engine applies gravity and friction and adds hspeed to x and vspeed to y. Angles in degrees: 0 = right, 90 = up, 180 = left, 270 = down.

Property What it is
hspeed Horizontal speed, in pixels per step. Positive = right.
vspeed Vertical speed, in pixels per step. Positive = down.
gravity Acceleration per step toward gravityDirection. 0 = no gravity.
gravityDirection Gravity direction, in degrees. Default 270.
friction How much the speed decreases per step, until it stops.
maxFallSpeed Limit of the downward vspeed. 0 = no limit.

The last four are also in the Physics section of the object Inspector.

Function What it does
speed() The current total speed.
setSpeed(value) Changes the speed, keeping the direction.
direction() The movement direction, from 0 to 360.
setDirection(degrees) Changes the direction, keeping the speed.
push(degrees, force) Adds speed in a direction.
moveToward(x, y, speed) Points at a position and sets the speed.
moveAndStop() Applies gravity and friction, moves by hspeed/vspeed and stops at solids. Once per step. Returns true if it hit something.
moveAndStop(dx, dy) Moves dx, dy pixel by pixel and stops against a solid, zeroing the speed on that axis.
onGround() true if there is a solid 1 pixel below the collision box.
hitFloor(), hitCeiling() The last moveAndStop hit the floor / the ceiling.
hitWall(), hitWallLeft(), hitWallRight() The last moveAndStop hit a wall.
function onUpdate(self)
self.hspeed = axis("esquerda", "direita") * 2
if pressed("pular") and self:onGround() then self.vspeed = -4.5 end
self:moveAndStop()
if self:hitWall() then self.hspeed = 0 end
end
  • Solids are instances with solid and tiles with collision.
  • On a step where moveAndStop moves, the automatic movement by hspeed/vspeed is skipped.
  • The direction is remembered while the instance is stopped: setSpeed(2) moves it the same way again.
  • Guide: Platformer.