raylib
stable2D/3D game and graphics toolkit wrapping the raylib C library, providing window management, drawing primitives, input handling, audio, textures, text, models, and camera control.
use plugin raylib::{init_window, close_window, window_should_close, …} Functions (21)
- init_window Open a window with given size and title
- close_window Close the window and free resources
- window_should_close True if window close was requested
- begin_drawing Begin frame rendering
- clear_background Fill background with a color
- set_target_fps Set desired frame rate
- color Build a packed color from r, g, b, a
- draw_rectangle Draw a filled rectangle
- draw_circle Draw a filled circle
- draw_line Draw a line between two points
- draw_text Draw text at a position
- get_frame_time Seconds elapsed since last frame
- get_time Total elapsed time in seconds
- get_fps Current frames per second
- is_key_pressed True if key was pressed this frame
- is_key_down True while key is held
- is_mouse_button_pressed True if mouse button pressed this frame
- get_mouse_position Current mouse cursor position
- take_screenshot Save a screenshot to a file
- get_screen_width Current window/screen width
- set_window_title Change the window title
Open a window with given size and title
Opens a new window. Must be called before any drawing or input functions.
use plugin raylib::{init_window, close_window, window_should_close,
begin_drawing, end_drawing, clear_background,
set_target_fps, WHITE}
init_window(800, 600, "My Game")
set_target_fps(60)
while !window_should_close() {
begin_drawing()
clear_background(WHITE())
end_drawing()
}
close_window()
Close the window and free resources
Closes the window and frees all raylib resources. Call this at the end of your program.
close_window()
True if window close was requested
Returns true when the user presses the close button or the escape key (unless overridden with set_exit_key).
while !window_should_close() {
// game loop
}
Begin frame rendering
Must bracket all drawing calls each frame. end_drawing swaps the back buffer to the screen.
begin_drawing()
clear_background(BLACK())
draw_text("Hello", 10, 10, 20, WHITE())
end_drawing()
Fill background with a color
Fills the entire frame with color. Call at the start of each frame inside begin_drawing.
use plugin raylib::{clear_background, RAYWHITE}
clear_background(RAYWHITE())
Set desired frame rate
Hints raylib to cap the frame rate. Does not guarantee exact timing.
set_target_fps(60)
Build a packed color from r, g, b, a
Packs RGBA byte values (0–255) into a single integer used by all drawing functions.
use plugin raylib::{color, draw_rectangle}
let red = color(255, 0, 0, 255)
draw_rectangle(10, 10, 100, 50, red)
Draw a filled rectangle
Draws a filled rectangle at pixel position (x, y).
use plugin raylib::{draw_rectangle, RED}
draw_rectangle(50, 50, 200, 100, RED())
Draw a filled circle
Draws a filled circle centered at (cx, cy).
use plugin raylib::{draw_circle, BLUE}
draw_circle(400, 300, 50.0, BLUE())
Draw a line between two points
Draws a 1-pixel-wide line between two points.
use plugin raylib::{draw_line, GREEN}
draw_line(0, 0, 800, 600, GREEN())
Draw text at a position
Draws a text string using raylib's built-in font.
use plugin raylib::{draw_text, DARKGRAY}
draw_text("Score: 42", 10, 10, 24, DARKGRAY())
Seconds elapsed since last frame
Returns the seconds elapsed since the last frame. Use this for frame-rate-independent movement.
use plugin raylib::{get_frame_time}
let dt = get_frame_time()
let player_x = player_x + speed * dt
Total elapsed time in seconds
Returns the total time in seconds since init_window was called.
let t = get_time()
let wave = (t * 2.0).sin()
Current frames per second
Returns the current measured frames per second.
use plugin raylib::{draw_text, get_fps, BLACK}
draw_text("FPS: {get_fps()}", 10, 10, 20, BLACK())
True if key was pressed this frame
Returns true only on the frame a key transitions from up to down. Use raylib key constants (integer codes).
use plugin raylib::{is_key_pressed}
if is_key_pressed(32) { // SPACE
print("jumped")
}
True while key is held
Returns true every frame while a key is held down.
use plugin raylib::{is_key_down}
if is_key_down(262) { // KEY_RIGHT
player_x = player_x + 200 * dt
}
Current mouse cursor position
Returns the current cursor position as #{x, y}.
use plugin raylib::{get_mouse_position}
let pos = get_mouse_position()
print("mouse at {pos["x"]}, {pos["y"]}")
Save a screenshot to a file
Saves the current frame to a PNG file.
use plugin raylib::{take_screenshot}
take_screenshot("screenshot.png")
Current window/screen width
Return the current window dimensions in pixels.
use plugin raylib::{get_screen_width, get_screen_height}
let cx = get_screen_width() / 2
let cy = get_screen_height() / 2
Change the window title
Updates the window title bar text at runtime.
use plugin raylib::{set_window_title}
set_window_title("Level 2 - Boss Fight")