loop¶
MiniLibX: mlx_loop
Runs the main loop. It shows your windows, calls your hooks about 60 times a second, and returns when there's nothing left to do.
Parameters¶
| Name | Type | Description |
|---|---|---|
mlx |
Mlx |
The connection from init |
Returns¶
None. loop returns when:
loop_endwas called; the current frame finishes first, or- every window of this
mlxhas been closed, by the user or withdestroy_windowordestroy_display.
Raises¶
| Exception | When |
|---|---|
KeyboardInterrupt |
Ctrl+C was pressed in the terminal. It's checked every frame. |
| anything | An exception raised by one of your hooks propagates out of loop unchanged. |
RuntimeError |
The window system failed to show a window (rare). |
What one frame does¶
- Calls the loop hook, if one is set.
- For each window: if the user closed it, removes it and queues its DestroyNotify (event 17). Otherwise it copies the window's pixels to the screen, then collects input since the last frame.
- Calls the event hooks for everything collected, in order.
- Returns if
loop_endwas called or no windows are left. Otherwise it starts the next frame.
Showing a window waits as needed to keep the loop at 60 fps at most. A slow loop hook makes frames slower; nothing is skipped. See The main loop for a full walkthrough.
Notes¶
- With no open windows,
loopreturns immediately. loopcan be called again after it returns. Windows that are still open keep their pixels and hooks.- Your hooks may call any malibx function, including
new_window,loop_hookandloop_end.
Example¶
import malibx
mlx = malibx.init()
win = malibx.new_window(mlx, 640, 480, "loop")
malibx.loop(mlx) # blocks until the window is closed
print("window closed, loop returned")