Standardbibliothek
Antra::Raylib
import Antra::Raylibraylib for Antra (antra-zig and the Perl interpreter), written in Antra on top of Antra::FFI.
A pipe-friendly API: a window with a frame loop, 2D shapes, text, images and textures, keyboard and mouse input, sound, timing, PNG snapshots of the screen, 3D (cameras, shapes, picking, meshes, models, animations), GLSL shaders and raylib's VR simulator.
The functions live in one package per module of raylib's cheatsheet (https://www.raylib.com/cheatsheet/cheatsheet.html); this package re-exports all of them, so there are two ways to use raylib:
- Everything under one name -
import Antra::Raylib as RL, thenRL.window(...),RL.circle(...),RL.cube(...), ... - Only the modules you need -
import Antra::Raylib::Coreandimport Antra::Raylib::Shapes, thenCore.window(...),Shapes.circle(...), ... Each module package works on its own.
| Package | Cheatsheet module | Contents |
|---|---|---|
Antra::Raylib::Core | rcore, rgestures, rcamera | window, frame loop, timing, input, cameras, modes, shaders, VR, screenshots |
Antra::Raylib::Shapes | rshapes | 2D shapes and 2D collisions |
Antra::Raylib::Textures | rtextures | images, textures, render textures, colors |
Antra::Raylib::Text | rtext | fonts, drawing and measuring text |
Antra::Raylib::Models | rmodels | 3D shapes, billboards, meshes, models, materials, animations, 3D collisions |
Antra::Raylib::Audio | raudio | audio device, sounds, music |
Antra::Raylib::Math | raymath | matrices, 2D/3D vectors, quaternions (v3_rotate, quat_slerp, ...) |
(Antra::Raylib::Base holds the shared internals and is not an API.
import Antra::Raylib::Math binds the name Math like Antra::Math;
import it as RMath when you need both.)
import Antra::Raylib as RL
val app = RL.window("Demo", 640, 360, [fps: 60]).!
RL.run(app, 0.0) |app, x, dt| -> {
app |> RL.clear(:raywhite)
|> RL.circle([int(x), 180], 30, :maroon)
|> RL.text("ESC quits", [10, 10], 20, :darkgray)
(x + 120 * dt) % 640
}
RL.close(app)The same with the module packages:
import Antra::Raylib::Core
import Antra::Raylib::Shapes
import Antra::Raylib::Text
val app = Core.window("Demo", 640, 360, [fps: 60]).!
Core.run(app, 0.0) |app, x, dt| -> {
app |> Core.clear(:raywhite)
|> Shapes.circle([int(x), 180], 30, :maroon)
|> Text.text("ESC quits", [10, 10], 20, :darkgray)
(x + 120 * dt) % 640
}
Core.close(app)Colors are [r, g, b], [r, g, b, a] or raylib's names (:raywhite,
:maroon, :skyblue, ...). Keys are keywords for special keys
(:left :right :up :down :space :enter :escape :tab :backspace, :f1..)
and one-character strings for letters and digits.
Needs the raylib shared library at runtime (libraylib.so / libraylib.dylib /
raylib.dll, release 6.2): antra native install with %{raylib: "6.2"} in
the project's native.and fetches it, or put it next to the script, in a
library path (-I) or the system search path, or call
RL.load_library(path) first.
Positions are [x, y] (3D: [x, y, z]), rectangles [x, y, width, height]; raylib's structs (textures, images, fonts, sounds, 2D cameras,
meshes, models) come back as maps and are passed back unchanged.
