Quick Start Guide
Get up and running with Xengine in just a few minutes.
Requirements
- .NET 6.0 SDK or later
- Visual Studio 2022, VS Code, or JetBrains Rider
- Windows, macOS, or Linux
Project Setup
Step 1: Create a New Project
Create a new .NET console application:
dotnet new console -n MyGame
cd MyGame
Step 2: Add Project References
Add references to the Xengine projects in your .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="path/to/Xengine.Engine.csproj" />
<ProjectReference Include="path/to/Xengine.Rendering.csproj" />
</ItemGroup>
</Project>
Step 3: Write Your First Code
Replace the contents of Program.cs:
using Xengine.Core;
using Xengine.Engine;
using Xengine.Math;
using Xengine.Scene;
using Xengine.Rendering;
// Configure the application
var config = new ApplicationConfig
{
WindowWidth = 1280,
WindowHeight = 720,
WindowTitle = "My Xengine Game"
};
// Create and initialize the engine
using var engine = new Engine(config);
engine.Initialize();
// Load a scene
var scene = engine.LoadScene("MainScene");
// Create a camera
var camera = scene.CreateGameObject("Camera", new Vector3(0, 10, -15));
camera.AddComponent<SimpleCamera>();
// Create a cube
var cube = scene.CreateGameObject("Cube", new Vector3(0, 1, 0));
cube.AddComponent<RotatingCube>();
// Create ground
var ground = scene.CreateGameObject("Ground");
ground.AddComponent<Ground>();
// Start the game loop
engine.Run();
// Simple camera component
public class SimpleCamera : Component
{
protected override void OnUpdate()
{
RaylibRenderer.Instance?.SetCamera(Transform!.Position, Vector3.Zero, 60f);
}
}
// Rotating cube component
public class RotatingCube : Component
{
private float _rotation;
protected override void OnUpdate()
{
_rotation += Time.Delta * 45f;
}
protected override void OnRender(RaylibRenderer r)
{
r.DrawCube(Transform!.Position, Vector3.One, Color.Blue);
}
}
// Ground plane component
public class Ground : Component
{
protected override void OnRender(RaylibRenderer r)
{
r.DrawPlane(Vector3.Zero, new Vector2(20, 20), new Color(0.3f, 0.3f, 0.3f));
r.DrawGrid(20, 1f);
}
}
Step 4: Run Your Game
dotnet run
Success!
You should see a window with a blue cube on a grid. The cube doesn't visually rotate yet because we're not applying the rotation - that's covered in the next tutorial!
Understanding the Code
ApplicationConfig
Configure your game window and settings:
| Property | Type | Description |
|---|---|---|
WindowWidth | int | Window width in pixels |
WindowHeight | int | Window height in pixels |
WindowTitle | string | Window title text |
TargetFrameRate | int | Target FPS (default: 60) |
VSync | bool | Enable vertical sync |
Engine Lifecycle
// 1. Create engine with config
using var engine = new Engine(config);
// 2. Initialize systems
engine.Initialize();
// 3. Load a scene
var scene = engine.LoadScene("MyScene");
// 4. Add objects and components to scene
// ...
// 5. Start the game loop
engine.Run();
// 6. Engine is disposed automatically (using statement)
Components
Components are where your game logic lives. Override these methods:
| Method | When Called |
|---|---|
OnAwake() | Once when component is created |
OnStart() | Once before first update |
OnUpdate() | Every frame |
OnFixedUpdate() | Fixed timestep (physics) |
OnLateUpdate() | After all updates |
OnRender() | When rendering the scene |
OnDestroy() | When component is destroyed |