Skip to content
Download

Platformer

  1. Floor and walls: check Solid on the object, or paint solid tiles.
  2. Player: in the Physics section, Gravity 0.25 and Max fall 4.5.
function onUpdate(self)
self.hspeed = axis("esquerda", "direita") * 1.5
if pressed("pular") and self:onGround() then self.vspeed = -4.5 end
self:moveAndStop()
end

moveAndStop() applies gravity and moves by hspeed/vspeed, stopping at solids. Call it once per step.

Face the movement direction and a shorter jump on release:

if self.hspeed ~= 0 then self.flipX = self.hspeed < 0 end
if released("pular") and self.vspeed < 0 then self.vspeed = self.vspeed * 0.5 end

Enemy that patrols back and forth:

function onUpdate(self)
self.hspeed = self.flipX and -0.5 or 0.5
self:moveAndStop()
if self:hitWall() then self.flipX = not self.flipX end
end
  • hitFloor() and hitCeiling() are true on the step the instance hit the floor or the ceiling.
  • If the collision box changes between animations, pick a sprite under Mask, in the object Inspector: collision then always uses its box.
  • The Platformer template, in New project, has a ready level.

Reference: Movement.