DEV Community

Vaclav Elias
Vaclav Elias

Posted on

Quick Start Guide to Stride Community Toolkit Preview: Code-Only Feature for C#/.NET Developers 🚀

Explore the Stride Community Toolkit's code-only feature to help C#/.NET developers build immersive 2D/3D games and visualizations, without the need for Game Studio. In this post, we'll walk through creating a simple game project using a .NET 8 Console App, by adding basic entities, implementing keyboard interaction, and add some motion.

Table of contents:

  • Introduction
    • Prerequisites
  • Setting Up the Project
    • Step 1: Create a New C# .NET 8 Console App
    • Step 2: Add the Code
    • Step 3: Build the Game
    • Step 4: Run the Game
  • Understanding the Code
  • Your Turn
  • References
  • Conclusion

Introduction 🌱

The Stride Community Toolkit is a collection of extensions and helpers designed for the Stride C# game engine. This open-source, community-driven project simplifies the process of creating 2D/3D games, especially using its code-only feature, which allows developers to build games without relying on Game Studio.

In this short guide, we'll use a .NET 8 Console App to create a basic game project, using just a few NuGet packages. If this piques your interest, be sure to check out the full tutorial linked at the end for more in-depth coverage.

Prerequisites 🏠

Basic knowledge of C# and .NET is required.

  1. Install the Microsoft Visual C++ 2015-2022 Redistributable (25MB) and restart your system if prompted.
  2. Install the .NET 8 SDK x64 (200MB).
  3. Install the IDE of your choice. I will be using Visual Studio 2022, but you can also use Visual Studio Code, Rider, or any other IDE that supports .NET development.

Setting Up the Project 💻

Step 1: Create a New C# .NET 8 Console App

Create a new C# .NET 8 Console App in your IDE and install the following NuGet package:

dotnet add package Stride.CommunityToolkit.Windows --prerelease
Enter fullscreen mode Exit fullscreen mode

Step 2: Add the Code

Here’s the core code for setting up your game:

using Stride.CommunityToolkit.Engine;
using Stride.CommunityToolkit.Rendering.ProceduralModels;
using Stride.Core.Mathematics;
using Stride.Engine;
using Stride.Games;
using Stride.Input;

float movementSpeed = 1f;
Entity? sphere1 = null;

using var game = new Game();

game.Run(start: Start, update: Update);

void Start(Scene rootScene)
{
    game.AddGraphicsCompositor();
    game.Add3DCamera().Add3DCameraController();
    game.AddDirectionalLight();
    game.Add3DGround();

    // Create a 3D primitive and add it to the scene
    sphere1 = game.Create3DPrimitive(PrimitiveModelType.Sphere, new()
    {
        IncludeCollider = false,
    });
    sphere1.Transform.Position = new Vector3(0, 0.5f, 0);
    sphere1.Scene = rootScene;
}

void Update(Scene scene, GameTime time)
{
    if (sphere1 == null) return;

    var deltaTime = (float)time.Elapsed.TotalSeconds;

    // Move sphere1 using keyboard input
    if (game.Input.IsKeyDown(Keys.Z))
    {
        sphere1.Transform.Position -= new Vector3(movementSpeed * deltaTime, 0, 0);
    }

    if (game.Input.IsKeyDown(Keys.X))
    {
        sphere1.Transform.Position += new Vector3(movementSpeed * deltaTime, 0, 0);
    }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Build the Game

Build the project from the command line or use your IDE to build it:

dotnet build
Enter fullscreen mode Exit fullscreen mode

Step 4: Run the Game

Run the application from your IDE, and you’ll see a sphere moving when pressing the Z and X key. 🎮

Image description

Understanding the Code

We started with a simple game loop using game.Run(). The Start() method initializes the game by adding a 3D camera, directional light, and ground plane to the scene. The sphere1 entity is positioned in the scene, and the Update() method handles the movement based on keyboard input.

  • Non-physical movement: We move sphere1 directly by modifying its Transform.Position. You can apply this approach to move objects freely without interacting with physics. This structure is highly extensible, allowing you to add more features like colliders, physics-based interactions, and UI components.

Your Turn

With just a few lines of code, you’ve built a simple game scene using the Stride Community Toolkit. Whether you’re developing a game or experimenting with 3D models, Stride’s code-only approach makes it easy for .NET developers to get started quickly.

References

Did I catch your attention? The full, comprehensive version of this tutorial is available here: Stride Community Toolkit Preview - Code-Only Feature Basics in C#.

Image description

Alternatively, if you're interested in F#, the condensed version of this article can be found here: Stride Community Toolkit Preview - Code-Only Feature Basics in F#. Yes, you can run this in F# 👀 too!

Visual Basic, you ask? 👀 Well, technically, you can, but that's not really my cup of tea. However, if you're curious, here's a super simple example: Capsule with rigid body in Visual Basic.

Conclusion

In this article, we explored the basics of game development with the Stride Community Toolkit’s code-only feature. You learned how to set up a .NET 8 Console App, add entities, and implement basic movement using keyboard inputs, all without using the Game Studio.

Now that you understand the foundations, it’s time to take these skills and start building more complex and interactive game projects. Keep experimenting and pushing the boundaries of what you can create with C# and .NET! 🎮🚀

Top comments (0)