Skip to content

BeanCheeseBurrito/Box2D.NET

Repository files navigation

Box2D.NET

Box2D.NET is a C# binding for Box2D. Low-level bindings to the C api are included and generated with Bindgen.NET. Native libraries are cross-compiled with Vezel-Dev's Zig Toolsets.

Note

There is currently no high-level wrapper but it may come in the future! Box2D.NET and Box2D.NET.Bindings are identical packages.

NuGet

You can download the nuget package and use Box2D.NET right away!

Box2D.NET (Wrapper + Bindings + Native Libraries): Release | Debug

dotnet add PROJECT package Box2D.NET.Release --version *-*

Box2D.NET.Bindings (Bindings + Native Libraries): Release | Debug

dotnet add PROJECT package Box2D.NET.Bindings.Release --version *-*

Box2D.NET.Native (Native Libraries): Release | Debug

dotnet add PROJECT package Box2D.NET.Native.Release --version *-*

Box2D.NET provides both release and debug packages for nuget. To include both of them in your project based on your build configuration, use the package references below. The latest stable or prerelease versions will be added to your project.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Box2D.NET.Debug" Version="*-*" Condition="'$(Configuration)' == 'Debug'" />
        <PackageReference Include="Box2D.NET.Release" Version="*-*" Condition="'$(Configuration)' == 'Release'" />
    </ItemGroup>

</Project>

GitLab Package Registry

For more up-to-date packages, development builds are available on the GitLab package registry. To add the development feed to your project, add the GitLab link below as a restore source. You can now reference any package version listed here!

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
        <RestoreAdditionalProjectSources>https://gitlab.com/api/v4/projects/53993416/packages/nuget/index.json</RestoreAdditionalProjectSources>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Box2D.NET.Debug" Version="0.0.4"/>
    </ItemGroup>

</Project>

Warning

Development feed packages may be deleted without warning to free up space.

Running examples

To run any of the example programs, use dotnet run and set the Example property's value to the example's full class name. Example:

dotnet run --project Box2D.NET.Examples --property:Example=HelloWorld

Building from source

Clone the repo

Clone the repo and it's submodules.

git clone --recursive https://github.com/BeanCheeseBurrito/Box2D.NET.git
cd Box2D.NET

Restore dependencies

Run the following command on the solution to restore all project dependencies.

dotnet restore

Generate bindings

Generate the binding code. Bindings are generated with Bindgen.NET.

dotnet run --project Box2D.NET.Bindgen

Build Box2D.NET

Compile the bindings and native libraries. The zig compiler will automatically be downloaded and cached in your local nuget package folder. Native libraries will be cross-compiled for linux, macos, and windows.

dotnet build

Reference the project

Reference the project and import the native libraries.

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
    </PropertyGroup>

    <Import Project="PATH/Box2D.NET/Box2D.NET.Native/Box2D.NET.Native.targets" />

    <ItemGroup>
        <ProjectReference Include="PATH/Box2D.NET/Box2D.NET/Box2D.NET.csproj" />
    </ItemGroup>

</Project>