ludic/docs/language/phases/phase-lateupdate.md

1.4 KiB

id name category kind tokens sig tip order
phase-lateupdate LateUpdate phases phase LateUpdate phase LateUpdate Runs each frame after Update and before Render. 4

LateUpdate runs once per frame, after every Update handler has finished and just before Render. Use it for logic that must observe the settled result of this frame's updates: following the camera to the player's new position, resolving queued despawns, or any end-of-step cleanup that would be wrong to do while other Update handlers are still moving models. The full per-frame order the engine runs is Input → FixedUpdate → Update → LateUpdate → Render, with Start running once at boot before any of them.

program FollowCamera {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  state FollowCameraState {
    camera_column: int = 0
  }

  handler SpawnPlayer phase Start {
    spawn Player { Position { column: 12, row: 0 } }
  }

  @Queries(these: [Position])
  handler MovePlayer phase Update {
    Position.column = Position.column + 1
  }

  # runs after MovePlayer, so the camera sees the final position
  @Queries(these: [Position])
  handler TrackPlayer(follow_camera_st: mut FollowCameraState) phase LateUpdate {
    follow_camera_st.camera_column = Position.column
  }
}