MiniLibX Hook Examples
This page will showcase some examples hooks that you can use with MiniLibX.
keycode
and mousecode
here are the MacOS ones, on Linux they are different (the escape key on Mac is 53, it's 65307 on Linux) and probably even different on Windows.
If you need to find what are hooks for MiniLibX, you can fin more information in the Events and Hooks chapter.
Here under I'll show you some examples hooks showing the most important values and some values that are not described in the documentation.
Simple key_pressed_handler
Since you can filter if you you want to listen to the keypress
or keyrelease
event, you can have two different key handlers, you might want to start doing something when we press the space
key and stop it only when you release it.
I think here you can see how you could find what keycode
corresponds to any key on your keyboard by looking at this function.
Simple mouse_handler
mlx_loop_hook
This hook will call a function every time through the MLX loop, we can use this to update what we show on screen. That's why I called it render
or draw
most of the time.
For example, in so-long
I use this hook to draw the map based on what changed. I draw the background completely again, to overwrite what was there, and then I redraw the walls and the player, but the player position can change based on keypressed
events so the player moves along.
The same way for collectibles, I don't want to draw them again if I already collected them (you can see the example I described here).
These are just examples and simple handlers so that you can better understand how this works and adapt it based on your needs.
Last updated
Was this helpful?