BonEngineSharp 1.5.4
See the version list below for details.
dotnet add package BonEngineSharp --version 1.5.4
NuGet\Install-Package BonEngineSharp -Version 1.5.4
<PackageReference Include="BonEngineSharp" Version="1.5.4" />
paket add BonEngineSharp --version 1.5.4
#r "nuget: BonEngineSharp, 1.5.4"
// Install BonEngineSharp as a Cake Addin #addin nuget:?package=BonEngineSharp&version=1.5.4 // Install BonEngineSharp as a Cake Tool #tool nuget:?package=BonEngineSharp&version=1.5.4
BonEngine Sharp
BonEngine
is a code-based game engine designed to be simple and straightforward, with as little setup as possible. It covers 2d rendering, assets, sound effects, music, input, config files, and more.
BonEngineSharp
is a C# bind of BonEngine
. The APIs are nearly identical, so in this doc we'll only cover few examples and not the whole API.
To view the full API you can check out API docs or the base BonEngine repo.
Install
To install use nuget:
Install-Package BonEngineSharp
Or grab the latest build from releases and add reference manually.
Important - no Any CPU
SinceBonEngineSharp
is a wrapper around a CPP library, your project needs to be built as either x86
or x64
, but it can't be Any CPU
. Same code can be used for both platforms, there's no difference in API or how you use the engine.
Platforms
BonEngineSharp
is built for .net core 3.0, and it uses a CPP library compiled for Windows Desktop (x86 or x64) with VS2019 tools.
If you want to build projects for different platforms, you need to build the CPP dlls yourself (from this repo).
Note that the CPP side is built with SDL and should be cross platform, but it wasn't officially tested or built for non-desktop targets.
How To Use
BonEngine
is very easy to setup:
using BonEngineSharp;
/// <summary>
/// A basic example scene.
/// </summary>
class MyScene : Scene
{
// called when scene loads
protected override void Load()
{
}
// called when scene unloads
protected override void Unload()
{
}
// called every frame to do updates
protected override void Update(double deltaTime)
{
}
// called every frame to draw scene
protected override void Draw()
{
}
// called every constant interval to update physics related stuff
protected override void FixedUpdate(double deltaTime)
{
}
}
/// <summary>
/// Start the application.
/// </summary>
static void Main(string[] args)
{
using (var scene = new MyScene()) {
BonEngine.Start(scene);
}
}
Once running, you can change your active scene:
Game.ChangeScene(newScene);
Managers
BonEngine
is divided into 7 subsystems, called managers
. These managers implement the vast majority of the engine's APIs, and they are:
Game
Application and global game stuff, like changing scene, exiting game, load config from file, retrieve delta time, ect.
Assets
Load and create assets - images, sound effects, music, config files, ect.
Gfx
Everything related to graphics and rendering.
Sfx
Everything related to sound effects and music.
Input
Implements user input, either by querying keyboard and mouse states or by checking "actions" which are bound to different keys.
Log
Provide basic logs.
UI
Provide UI system.
Diagnostics
Get diagnostics and debug data, like FPS, number of draw calls, ect.
Some Examples
Lets review some simple examples (note: more examples can be found under the BonEngineSharpTest
project).
Drawing Images - Gfx.DrawImage()
using BonEngineSharp;
using BonEngineSharp.Assets;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// image to draw
private ImageAsset _srcImage;
// called when scene loads - load image from file
protected override void Load()
{
_srcImage = Assets.LoadImage("my_image.png");
}
// called every frame to draw scene - draw image
protected override void Draw()
{
Gfx.DrawImage(_srcImage, new PointI(100, 100));
}
}
Drawing Shapes - Gfx.DrawRectangle()
using BonEngineSharp;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// called every frame to draw scene - draws a rectangle
protected override void Draw()
{
Gfx.DrawRectangle(new RectangleI(50, 50, 25, 25), Color.Red, true);
}
}
Drawing Text - Gfx.DrawText()
using BonEngineSharp;
using BonEngineSharp.Assets;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// font to use
private FontAsset _font;
// called when scene loads - load font to use
protected override void Load()
{
_font = Assets.LoadFont("OpenSans-Regular.ttf", 32);
}
// called every frame to draw scene - draw text
protected override void Draw()
{
Gfx.DrawText(_font, "Hello BonEngine!", new PointF(50, 50));
}
}
Drawing Sprites - Gfx.DrawSprite()
using BonEngineSharp;
using BonEngineSharp.Assets;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// sprite to draw
private Sprite _sprite;
// called when scene loads - setup sprite
// note: spritesheets and animations exists in the engine, but are not covered in this example
protected override void Load()
{
_sprite = new Sprite()
{
Position = new PointF(500, 500),
Origin = new PointF(0.5f, 1.0f),
Image = Assets.LoadImage("sprite.png")
};
}
// called every frame to draw scene - draw sprite
protected override void Draw()
{
Gfx.DrawSprite(_sprite);
}
}
Playing Music - Sfx.PlayMusic()
using BonEngineSharp;
using BonEngineSharp.Assets;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// music to play
private MusicAsset _music;
// called when scene loads - load and starts playing music
protected override void Load()
{
_music = Assets.LoadMusic("my_song.ogg");
Sfx.PlayMusic(_music);
}
}
Playing Sounds - Sfx.PlaySound()
using BonEngineSharp;
using BonEngineSharp.Assets;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// music to play
private SoundAsset _sound;
// called when scene loads - load and plays sound effect once
protected override void Load()
{
_sound = Assets.LoadSound("boom.wav");
Sfx.PlaySound(_sound, 100, 0);
}
}
Getting Input - Input.Down() / Input.CursorPosition
using BonEngineSharp;
using BonEngineSharp.Framework;
class MyScene : BonEngineSharp.Scene
{
// called every frame to control player
protected override void Update(double deltaTime)
{
// check bound action
if (Input.Down("left"))
{
// move left
}
// check key directly
if (Input.Down(KeyCodes.KeySpace))
{
// attack
}
// get mouse position
var mouse = Input.CursorPosition;
}
}
License
This lib is distributed with the MIT license, so you can do pretty much anything (legal) with it 😃
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.5.5 | 510 | 7/3/2021 |
1.5.4 | 398 | 1/13/2021 |
1.5.3 | 343 | 1/11/2021 |
1.5.2 | 364 | 1/9/2021 |
1.5.1 | 358 | 1/8/2021 |
1.4.1 | 464 | 12/11/2020 |
1.4.0 | 427 | 11/30/2020 |
1.3.31 | 607 | 11/27/2020 |
1.3.3 | 387 | 11/24/2020 |
1.3.2 | 470 | 11/7/2020 |
1.3.1 | 488 | 8/31/2020 |
1.3.0 | 474 | 8/24/2020 |
1.2.6 | 573 | 8/1/2020 |
1.2.5 | 466 | 7/10/2020 |
1.2.4 | 487 | 7/5/2020 |
1.2.3 | 465 | 7/3/2020 |
1.2.2 | 600 | 6/27/2020 |
1.2.1 | 464 | 6/23/2020 |
1.1.0 | 505 | 6/13/2020 |
Fixed alpha channels for images without alpha, added round pixels feature, and added some extras.