Step order
Fixed step
Section titled “Fixed step”Brasa runs the game logic in fixed steps of 1/60 of a second, independent of the speed of the computer. If a frame takes long, it runs more steps to catch up (at most 5 per frame). That’s why speeds in “pixels per step” and timers in “steps” behave the same on any machine.
Inside a step
Section titled “Inside a step”For all the instances, in this order:
- Timers: the
after/everythat are due are run. onUpdateof each instance, in the order in which they were created.- Movement: gravity and friction adjust the speed,
hspeed/vspeedmove the instance (unlessmoveAndStophas already moved it on this step) and the animation advances. - Collisions: the
onCollideof whoever is touching. - Destructions: the instances with
destroy()leave, and theironDestroyis called. - New instances: the ones created during the step join the list. Their
onSpawnalready ran at the time of thespawn, but the firstonUpdateonly happens on the next step. - Camera: the room’s camera moves one step behind the target, with the smoothing and the dead zone. Since it moves on the fixed step, the smoothing is the same on any monitor, 60 Hz or 144 Hz.
After the steps, the frame is drawn: all the visible instances run onRender (the layers at the back first) and, on top of everything, onRenderGui. The position of the camera is rounded to a whole pixel at drawing time, so the character and the scenery change pixels together.
Practical consequences
Section titled “Practical consequences”- A position changed in
onUpdatealready applies to the collisions of the same step. destroy()doesn’t remove right away: the instance finishes the step and leaves at the end of it. UseisDestroyed()so you don’t act twice.goToandrestarthappen at the end of the frame, after the current step finishes.
