[All] Consider wrapping raylib structs and methods into managed classes
See original GitHub issueBefore submitting a new issue, please verify and check:
- The issue is specific to Raylib-cs and not raylib
- I checked there is no similar issue already reported
- My code has no errors or misuse of Raylib-cs
Issue description
I came across raylib-cpp recently and was wondering if maybe a similar approach would be good for raylib-cs https://github.com/RobLoach/raylib-cpp
Environment
NA
Issue screenshot
NA
Code example
int screenWidth = 800;
int screenHeight = 450;
Window window = new Window(screenWidth, screenHeight, "raylib-cs - basic window");
Texture logo = new Texture("raylib_logo.png");
window.SetTargetFPS(60);
while (!window.ShouldClose())
{
window.BeginDrawing();
window.ClearBackground(RAYWHITE);
var text = "Congrats! You created your first window!"
text.Draw(190, 200, 20, LIGHTGRAY);
// Object methods.
logo.Draw(
screenWidth / 2 - logo.GetWidth() / 2,
screenHeight / 2 - logo.GetHeight() / 2);
window.EndDrawing();
}
// UnloadTexture() and CloseWindow() are called automatically using finalizer and IDisposable.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:18 (10 by maintainers)
Top Results From Across the Web
Issues · ChrisDill/Raylib-cs
C# bindings for raylib, a simple and easy-to-use library to learn ... [All] Consider wrapping raylib structs and methods into manag.
Read more >raylib - cheatsheet
Don't miss latest functions added to raylib... check raylib cheatsheet. ... does this job: draws everything + SwapScreenBuffer() + manage frame timing + ......
Read more >Creating Raspberry Pi applications with Raylib and Ruby
As discussed above, the SWIG-generated extension defines Ruby classes for each C struct it encounters. Whereas Raylib heavily uses stack- ...
Read more >Help with structs? : r/raylib
I'm trying to wrap rayLib for OpenXTalk The help I have said: struct Color; [ 4 bytes] - // RGBA values, 4 char,...
Read more >Creating Raspberry Pi applications with Raylib and Ruby
To wrap around an entire library like Raylib, each function that needs to be available in Ruby needs a wrapper function, complete with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This would make the bindings rather opinionated and force users to write code in a specific way, potentially kneecapping non-standard/common architectures. I would suggest leaving this to downstream frameworks and libraries.
I believe we want Raylib-cs to be a direct bindings to raylib; choosing a design pattern should be left up to users.
I think getting rid of structs is not possible, because we directly use them to interop with the native raylib library. Raylib c uses structs as well.
Heres an example:
This is the color struct: https://github.com/ChrisDill/Raylib-cs/blob/master/Raylib-cs/types/Color.cs
Raylib doesn’t support multiple windows as well: https://github.com/raysan5/raylib/wiki/Use-multiple-windows
Writing a Window class in C# would require you to use a singleton. Using finalizers doesn’t work either since dotnet core. U will have to implement IDisposable and/or use the ProcessExit event in AppDomain: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/finalizers
So here is an example of how this could look like:
This is the main method: