-
Notifications
You must be signed in to change notification settings - Fork 77
Home
Raylib-cs is set of C# bindings for raylib, a simple and easy-to-use library to learn videogames programming.
Raylib-cs is designed to be close to the original api however there are some differences to make it easier to use in C# without limiting you to a specific approach.
Raylib-cs has wrapper functions around functions that take in strings to make them
easier to use. For example InitWindow
takes in a string for the title.
// Example usage
Raylib.InitWindow(800, 450, "åäö");
Originally used MarshalAs attributes to handle this but switched to a unsafe/safe approach to provide users with more control and to make the marshalling code more explicit internally. Note that the safe utils involve additional memory allocation marshalling the data across.
Raylib-cs color presets are stored as static in the Color
struct. This is more consistent with other types in C#.
// Example usage
Raylib.ClearBackground(Color.RayWhite);
Raylib.BeginDrawing();
Raylib.DrawRectangle(0, 0, 100, 100, Color.Red);
Raylib.EndDrawing();
Raylib-cs enums are used as the intended type instead of int
for type safety and ease of use.
// Example usage
if (Raylib.IsKeyPressed(KeyboardKey.Enter))
{
}
if (Raylib.IsMouseButtonPressed(MouseButton.Left))
{
}
Raylib-cs depends on System.Numerics
for math types to make it easier to use
with other libraries and to provide a nicer api for math operations.
// Example usage
Vector2 a = Vector2.Zero;
Vector3 b = Vector3.Zero;
Matrix4x4 m = Matrix4x4.Identity;
Quaternion q = Quaternion.Identity;
Note that the matrix layout in raylib is different to System.Numerics
. When data is passed to/from raylib, you may need to transpose
the matrix to make sure it is in the right order for any operations you need to do.