Create Project
Command Line and Visual Studio Code Instructions
The following instructions will guide you through creating a new Stride project using the command line. If you prefer to use Visual Studio Code, you can follow the same steps in the Visual Studio Code Terminal.
Prerequisites: Ensure you have all the prerequisites installed. Refer to the Prerequisites section for more information.
Create a Console App: Follow the Microsoft tutorial to learn more about creating a new console application. Use the following command:
dotnet new console --framework net8.0
Add NuGet Package: Execute the following command to add the necessary NuGet package.
dotnet add package Stride.CommunityToolkit.Windows --prerelease
Update Program.cs: Paste the example code provided below into your
Program.cs
file.Build the Project (Optional): The
dotnet build
command is used to compile your Stride project, generating executable files and checking for any errors in your code. This step is optional as the subsequentdotnet run
command will automatically build the project if it hasn't been built already. To manually build the project, execute the following command:dotnet build
Run the Project: The
dotnet run
command will build (if necessary) and execute your project. Run the following command to start your Stride project:dotnet run
Enjoy Stride: If everything is set up correctly, you should now be able to run and enjoy your Stride project.
Visual Studio 2022 and Rider Instructions
- Create a C# Console Application: Open Visual Studio 2022 or Rider and create a new C# Console Application targeting .NET 8.
- Add NuGet Package: Search for and add the
Stride.CommunityToolkit.Windows
NuGet package, ensuring you opt for the pre-release version.- This package will install all the necessary Stride NuGet packages.
- Update Program.cs: Paste the example code (provided below) into your
Program.cs
file. - Run the Project: Build and run your project using the IDE's run functionality.
- Enjoy Stride: If everything is set up correctly, you should now be able to run and enjoy your Stride project.
Example Code
The provided C# code example demonstrates the basic usage of the Stride Game Engine.
using Stride.CommunityToolkit.Engine;
using Stride.CommunityToolkit.Rendering.ProceduralModels;
using Stride.Core.Mathematics;
using Stride.Engine;
using var game = new Game();
game.Run(start: Start);
void Start(Scene rootScene)
{
game.SetupBase3DScene();
var entity = game.Create3DPrimitive(PrimitiveModelType.Capsule);
entity.Transform.Position = new Vector3(0, 8, 0);
entity.Scene = rootScene;
}
using var game = new Game();
creates a new instance of theGame
class.- The
game.Run(start: Start);
line starts the game, and it specifies that theStart
method should be called when the game begins. void Start(Scene rootScene)
is the method that is called when the game starts. It takes in aScene
object, which represents the game scene that is currently being played.- Inside the
Start
method,game.SetupBase3DScene();
sets up a basic 3D scene. var entity = game.Create3DPrimitive(PrimitiveModelType.Capsule);
creates a new primitive entity of typeCapsule
, and assigns it to theentity
variable.entity.Transform.Position = new Vector3(0, 8, 0);
sets the position of the entity in the 3D space. The position is set to (0, 8, 0), which means the capsule is placed 8 units above the ground.entity.Scene = rootScene;
adds the entity to the root scene of the game. This step is crucial because assigning the entity to the scene ensures it is rendered and visible in the game. Without this assignment, the entity would not be part of the scene graph, and therefore, it would not appear in the game.
The Create3DPrimitive()
method creates a Capsule with rigid body physics. Since the capsule is placed 8 units above the ground, it will fall due to gravity.
Tip
It's important to remove the capsule from memory once it's no longer visible in the scene to free up resources and ensure the CPU isn't unnecessarily calculating physics for it.
Additional Examples
Explore more examples listed in the menu on the left, categorized by programming language and level of complexity. These examples provide a deeper understanding of how to work with a code-only project in Stride, showcasing various functionalities and implementations.
The examples are organized under the following sections:
- C# Basic Examples: Basic examples demonstrating fundamental concepts using C#.
- C# Advanced Examples: Advanced scenarios and implementations using C#.
- F# Basic Examples: Fundamental concepts demonstrated using F#.
- VB Basic Examples: Fundamental concepts demonstrated using Visual Basic.
To view an example, click on its name in the menu, and you will be navigated to a page with a detailed explanation and code snippets.