raylib ffi bindings for Dart. The API is essentially consistent with C.
import 'package:raylib_dart/raylib_dart.dart';
int main() {
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText(
"Congrats! You created your first window!",
190,
200,
20,
LIGHTGRAY,
);
EndDrawing();
}
CloseWindow();
return 0;
}The first time you run the following command, it will compile raylib and generate dynamic libraries, which will take some time.
dart run example/core_basic_window.dartint main(void)int main()Use Dart's dot-shorthand syntax:
IsKeyDown(KEY_RIGHT);IsKeyDown(KEY_RIGHT); // Deprecated
IsKeyDown(.right); // RecommendedFor Vector2, Vector3, Matrix, Ray, etc., use vector_math.
Use the image package.
Merged into a single RandomSequence:
int* seq = LoadRandomSequence(count, min, max);
UnloadRandomSequence(seq);final seq = RandomSequence(count, min, max);- SetLoadFileDataCallback
- SetSaveFileDataCallback
- SetLoadFileTextCallback
- SetSaveFileTextCallback
Example using SetLoadFileDataCallback:
// Use raylib's default callback
SetLoadFileDataCallback(); // or SetLoadFileDataCallback(null);
// Hook with Dart
SetLoadFileDataCallback((filename) => File(filename).readSync());- TraceLog
- MemAlloc
- MemRealloc
- MemFree
- LoadFileData
- UnloadFileData
- SaveFileData
- ExportDataAsCode
- LoadFileText
- UnloadFileText
- SaveFileText
- SetGamepadMappings
- SetTraceLogCallback: Could be merged into logging
- Keep function names unchanged
- Preserve original enumerations and constants
For example, enumerations are recommended to use dot-shorthand syntax to simplify code. Keep the original constants but mark them as Deprecated, and provide the recommended usage.
Color color = RED; // Deprecated
Color color = .red; // Recommended
KeyboardKey key = KEY_A; // Deprecated
KeyboardKey key = .a; // Recommended