Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming

Overview

Raylib Logo

Haxe bindings for raylib, a simple and easy-to-use library to learn videogame programming, Currently works only for windows but feel free the expand to other platforms. This binding is worked on by two people, but if you want to work on the binding feel free to add the feature and make a pull request.

Warning! The binding is in its early stage of development and may change at any moment, please use at your own risk

Requirements

  • Haxe 4.0.0 or above
  • If you are on windows:
    • MSVC v142 - VS 2019 C++ x64/x86 build tools
    • Windows 10 SDK

Installation

To install hxRaylib just run haxelib git hxRaylib https://github.com/ForeignSasquatch/hxRaylib.

Usage

In your project make a Build.hxml file with the following:

-cp src
-cpp bin
-lib hxRaylib
-main Main
# Uncomment for the platform
#-D mac
#-D windows
#-D linux

Put a Main.hx file in the src/ directory with your Main class such as the example below.

Example

This is a basic example of the binding which creates a window

import Raylib.*;
import Raylib.Colors.*;

class Main
{
    static function main()
    {
        InitWindow(800, 450, "hxRaylib");

        while (!WindowShouldClose())
        {
            BeginDrawing();
                ClearBackground(RAYWHITE);
                DrawText("Congrats! You created your first window using hxRaylib!", 100, 100, 20, BLACK);
            EndDrawing();
        }

        CloseWindow();
    }
}

License

hxraylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

Thanks to:

Comments
  • Vector2.create() generates broken code.

    Vector2.create() generates broken code.

    trying to do this

    image

    generates this in the C++ file

    image

    Which triggers the following error when trying to compile error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

    opened by thepercentageguy 8
  • Invalid signature of DrawTextureRec

    Invalid signature of DrawTextureRec

    Hi! :wave: It's my first day with haxe and raylib. I tried to draw an image and I had a problem with using DrawTextureRec. According to the cheatsheet the function should accept a vector and a rectangle, but the bindings say that it should be two rectangles.

    Compare this

    void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint);  // Draw a Texture2D with extended parameters
    

    to this

    @:native("DrawTextureRec") static function DrawTextureRec(texture:Texture2D, source:Rectangle, dest:Rectangle, tint:Color):Void;
    

    So it seems like there's a bug in the version available for haxe? :thinking:

    Cheers!

    opened by mcjlnrtwcz 2
  • First commit for Haxe to JS backend

    First commit for Haxe to JS backend

    This marks the start of the JS backend.

    The plan is to first port rlgl.h to an Haxe class in order to replicate the original API and to make things much easier, then the core module comes into place and the other will follow

    opened by rc-05 2
  • Camera2D fixes

    Camera2D fixes

    The extern class Camera2D is a c struct and when calling the create function it was being created as an empty struct and so the fields in the class were not set.

    I added arguments to the create function so that the initial values can be passed in and the struct will not be empty.

    When I was trying to set the x value of target within the Camera2D class I was seeing the error base operand of ‘->’ has non-pointer type ‘Vector2‘. The generated c code was camera.target->x = x; The fix for this error is usually to add @:structAccess to the extern binding but this was already present.

    By changing the field types used in the extern bindings from Vector2 to RlVector2 there is no more error and the fields can be set as expected. I think this is due to Vector2 being a typedef that wraps RlVector2 in cpp.Struct which confuses matters -

    typedef Vector2 = cpp.Struct<RlVector2>;
    
    opened by jobf 1
  • Enable pattern matching on Rl.Keys

    Enable pattern matching on Rl.Keys

    The following code would produce the error Only inline or read-only (default, never) fields can be used as a pattern

    switch Rl.getKeyPressed() {
     case Rl.Keys.UP: handle_up();
     case _: 
    }
    

    Removing static from the fields within enum abstract Keys fixes this.

    I also added to and from rules for easier casting. This negates the need for the explicit Int type hint.

    opened by jobf 1
  • Enum naming convention

    Enum naming convention

    So I've noticed that there are two conventions as for the enums:

    • repeating the prefix: e.g. MOUSE_CURSOR_DEFAULT -> Raylib.MouseCursor.MOUSE_CURSOR_DEFAULT
    • not repeating the prefix: e.g.MOUSE_BUTTON_LEFT -> Raylib.MouseButton.LEFT

    The shorter seam nicer but either is better than both imo.

    Not sure if worth the hustle though - let me know; I can prepare a pr for that.

    opened by robertnorenberg 1
  • 'w' is not a member of Rectangle

    'w' is not a member of Rectangle

    Hello, when i'm trying to create a Rectangle and then draw on screen, I get this error when i compile.

    Here is the code i'm using.

    import Raylib.Rectangle;
    import Raylib.Colors;
    import Raylib.*;
    
    class Main
    {
        static function main()
        {
            var screenWidth = 800;
            var screenHeight = 450;
            InitWindow(screenWidth, screenHeight, "Draw a rectangle");
            SetTargetFPS(60);
    
            var rect = Rectangle.create(100, 100, 36, 36);
            while(!WindowShouldClose())
            {
                
                BeginDrawing();
                    DrawRectangle(Std.int(rect.x), Std.int(rect.y), Std.int(rect.w), Std.int(rect.h), Colors.RED);
                EndDrawing();
            }
    
            CloseWindow();
        }
    }
    
    opened by Caresle 1
  • Added @:structAccess to Music extern class + Use precompiled header file on Linux

    Added @:structAccess to Music extern class + Use precompiled header file on Linux

    Now the code gets compiled ~~but for some reason the Music releated functions are not found by the linker, this will need to be investigated~~ and the program links correctly.

    opened by rc-05 1
  • has no field DrawText"">

    "Class has no field DrawText"

    I've installed the library and all the dependencies but unfortunately the example in your ReadMe doesn't work out of the box.

    I get the following error: src/Main.hx:14: characters 24-32 : Class<Raylib> has no field DrawText

    If I remove line 14 it compiles and runs perfectly, no issues. But it doesn't like the call to DrawText().

    I assume this function has been implemented otherwise you wouldn't put it in your ReadMe as an example, so maybe something's broken in the library?

    opened by FletcherCutting 1
  • raygui edits

    raygui edits

    Corrected some spelling errors and made the bindings use the same function names as original Raygui so that examples and documentation are easier to follow.

    Also simplified the GuiState enum (see #27 for reasoning).

    opened by jobf 0
  • Wrap aliased RlColor in cpp.Struct

    Wrap aliased RlColor in cpp.Struct

    I was seeing error: cannot convert ‘Dynamic’ to ‘Color’ when passing a Color as a constructor argument.

    A helpful bit of info from the haxe discord -

    constructor arguments must be "dynamic compatible" on hxcpp which externs representing native structs won't be, try wrapping the struct in a cpp.Struct for the constructor argument

    This explains why there are lots of this in the bindings -

    typedef Foo = cpp.Struct<Bar>;
    

    e.g. as seen in the commit, this allows Color to be passed as a constructor argument -

    typedef Color = cpp.Struct<RlColor>;
    
    opened by jobf 0
  • Erratic casting in `Rl.Image` variable declaration

    Erratic casting in `Rl.Image` variable declaration

    Haxe Code:

    class Main {
    	static function main() {
    		var logo:Rl.Image = Rl.loadImage("Assets/logo.png")
    		Rl.imageFormat(logo, Rl.PixelFormat.UNCOMPRESSED_R8G8B8A8);
    		Rl.initWindow(800, 450, "Spatial");
    		Rl.setWindowIcon(logo);
    		...
    

    C++ Output:

    	void Main_obj::main(){
    	            	HX_STACKFRAME(&_hx_pos_e47a9afac0942eb9_4_main)
    	HXLINE(   5)		const char* this1 = HX_("assets/logo.png",72,b4,d1,0d).utf8_str();
    	HXDLIN(   5)		cpp::Struct< Image > logo = LoadImage(this1);
    	HXLINE(   6)		ImageFormat(&(logo),PIXELFORMAT_UNCOMPRESSED_R8G8B8A8);
    	HXLINE(   7)		const char* this2 = HX_("Spatial",a4,f0,48,6a).utf8_str();
    	HXDLIN(   7)		InitWindow(800,450,this2);
    	HXLINE(   8)		SetWindowIcon(logo);
    

    Build Output;

    Error: Main.cpp
    ./src/Main.cpp(34): error C2664: 'void ImageFormat(Image *,int)': cannot convert argument 1 from 'cpp::Struct<Image,cpp::DefaultStructHandler> *' to 'Image *'
    ./src/Main.cpp(34): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    C:/Users/ACER/Code/Haxe/lib/raylib-hx/source/lib/src/raylib.h(1231): note: see declaration of 'ImageFormat'
    
    opened by zikaora 5
Releases(4.0)
Owner
FSasquatch
Creator of hxRaylib, Lover of haxe, c# and Hater of C++
FSasquatch
autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of `unsafe`

Raylib-CsLo Raylib-CsLo LowLevel autogen bindings to Raylib 4.0 and convenience wrappers on top. Requires use of unsafe A focus on performance. No run

NotNot 69 Dec 18, 2022
SWIG bindings for raylib (to Lua, and hopefully other languages)

swigraylib SWIG binding for raylib This repo generates raylib bindings to other languages (eg. Lua), by providing a raylib.i SWIG interface file. SWIG

null 6 Oct 28, 2021
A simple and easy-to-use library to enjoy videogames programming

hb-raylib v3.5 Harbour bindings for raylib 3.5, a simple and easy to use library to learn videogames programming raylib v3.5. The project has an educa

MarcosLMG 1 Aug 28, 2022
Utilities and common code for use with raylib

Utilities and shared components for use with raylib

Jeffery Myers 86 Dec 1, 2022
The Ultimate Raylib gaming library wrapper for Nim

NimraylibNow! - The Ultimate Raylib wrapper for Nim The most idiomatic and up-to-date wrapper for Raylib gaming C library. Use this library if you wan

Dmitry Matveyev 138 Dec 22, 2022
Minimalistic assertion library for raylib.

raylib-assert Minimalistic assertion library for raylib. Example #include "raylib.h" #include "raylib-assert.h" int main(void) { Assert(10 == 10)

Rob Loach 2 Jan 12, 2022
Integrate PhysFS with raylib, allowing to load images, audio and fonts from data archives.

raylib-physfs Integrate the virtual file system PhysicsFS with raylib, allowing to load images, audio, and fonts from data archives. Features Load the

Rob Loach 21 Dec 3, 2022
My collection of raylib code examples - For learning the C language with 2D and 3D games.

Raylib-Examples My collection of raylib examples. ( https://www.raylib.com/index.html ) For Raylib Version of 4 april 2020 ( Notepad++ windows install

Rudy Boudewijn van Etten 49 Dec 28, 2022
Load Aseprite files for animated sprites in raylib.

raylib-aseprite Load Aseprite .aseprite files for animated sprites in raylib. Features Load Aseprite files directly for use in raylib Draw individual

Rob Loach 30 Dec 20, 2022
A pong clone written in C++ with Raylib

How To Play Objective: first player to reach 10 points is the winner! PLAYER 1: W: up S: down PLAYER 2: ARROW UP or I: up ARROW DOWN or S: down Requir

Victor Sarkisov 1 Nov 8, 2021
Pong clone made in C++ with raylib

Raypong Pong clone made in C++ with raylib. Dependencies ...C++ and raylib lol Building To build, use these commands: mkdir build # Create a build dir

Mars 0 Feb 4, 2022
raylib Nuget package

raylib Nuget package This is a Nuget package for the popular raylib video game programming library. Resources used to create this package are as follo

Samuel Gomes 6 Dec 5, 2022
A top-down shooter made for the raylib 5K gamejam.

ANTISPELL Description A top-down shooter where you have to use your enemies' attacks to spell your spells! Features Absorb letters getting close to en

Francisco Javier Andrés Casas Barrientos 3 Apr 9, 2022
RapidObj is an easy-to-use, single-header C++17 library that loads and parses Wavefront .obj files.

RapidObj About Integration Prerequisites Manual Integration CMake Integration API RapidObj Result Next Steps OS Support Third Party Tools and Resource

Slobodan Pavlic 108 Jan 2, 2023
An easy-to-use C library for displaying text progress bars.

What is this thing? progressbar is a C-class (it's a convention, dammit) for displaying attractive progress bars on the command line. It's heavily inf

Trevor Fountain 440 Dec 27, 2022
A WIP "Vulnerable by Design" kext for iOS/macOS to play & learn *OS kernel exploitation

Vulnerable Kext A WIP (work-in progress) "Vulnerable by Design" kext for iOS/macOS to play/learn with *OS kernel exploitation Usage Documentation can

Chaithu 221 Dec 11, 2022
Python bindings for Wasm3, the fastest WebAssembly interpreter

pywasm3 Python bindings for Wasm3, the fastest WebAssembly interpreter Main repository: Wasm3 project Install # Latest release: pip3 install pywasm3

Wasm3 Labs 49 Dec 27, 2022
A linux library to get the file path of the currently running shared library. Emulates use of Win32 GetModuleHandleEx/GetModuleFilename.

whereami A linux library to get the file path of the currently running shared library. Emulates use of Win32 GetModuleHandleEx/GetModuleFilename. usag

Blackle Morisanchetto 3 Sep 24, 2022
runsc loads 32/64 bit shellcode (depending on how runsc is compiled) in a way that makes it easy to load in a debugger. This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras.

runsc This code is based on the code from https://github.com/Kdr0x/Kd_Shellcode_Loader by Gary "kd" Contreras and contains additional functionality. T

null 24 Nov 9, 2022