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.
Properties
Section titled “Properties”| 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.
Functions
Section titled “Functions”| 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 endendvoid onUpdate() override { hspeed = axis("esquerda", "direita") * 2; if (pressed("pular") && onGround()) vspeed = -4.5f;
moveAndStop(); if (hitWall()) hspeed = 0;}- Solids are instances with
solidand tiles with collision. - On a step where
moveAndStopmoves, the automatic movement byhspeed/vspeedis skipped. - The direction is remembered while the instance is stopped:
setSpeed(2)moves it the same way again. - Guide: Platformer.
