-
Notifications
You must be signed in to change notification settings - Fork 0
Creating your first game
To start, you will need to have a copy of the engine, you can follow the Installing and Building guide for that.
In the VoltstroEngine solution, create a new project that uses the template 'Class Library (.NET Core)'.
Give the project the name of your game. For this example we will use the name 'TestGame'.
The default project configuration isn't correct. You will need to edit you project's .csproj
file. In visual Studio you can do that by just double clicking the your project.
Now edit your .csproj
file to look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Platforms>x64</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutputPath>../../game/bin/Debug/TestGame/bin/</OutputPath>
<DefineConstants>DEBUG;TRACE;PROFILE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>../../game/bin/Release/TestGame/bin/</OutputPath>
</PropertyGroup>
</Project>
Please note the <OutputPath>
should output to your game's correct path. So if your game name was 'CrapOut' the output directory would be ../../game/bin/Debug/CrapOut/bin/
.
We also need to fix our solution, as the configuration Any CPU
was added back.
So go to Visual Studio Configuration Manager and remove it.
In your project, add the VoltstroEngine project as a dependency to your project.
We need to create an entry point so the engine knows where to create the app. In your TestGame project create a new C# file and give it a name like 'EntryPoint'.
Make the EntryPoint class inherit from IEntryPoint
, and implement the CreateApplication
and GetGameName
methods. Make sure the class is public!
For the GetGameName
method make it return the EXACT name of your project. So four our example TestGame
.
Now to create the App class. Create a new C# file and give it name like 'GameApp', make it inherit from Application
.
Back in our EntryPoint class, make the CreateApplication
method return the new GameApp class we created.
Your final files should look like this:
EntryPoint.cs:
public class EntryPoint : IEntryPoint
{
public Application CreateApplication()
{
return new GameApp();
}
public string GetGameName()
{
return "TestGame";
}
}
GameApp.cs
public class GameApp : Application
{
}
This is the final step, we need to create a game layer so we can tell the engine to do stuff.
Start by creating a new class in the GameApp.cs file called something like 'GameLayer', and make it inherit ILayer
, and implement the required methods.
You should have four methods, all of which are pretty self explanatory. In your OnUpdate
method, add:
RenderingAPI.Clear(); //Clears the buffers
RenderingAPI.SetClearColor(0, 0, 0); //Sets the screen to black
Now one last thing, in our GameApp
class, add a constructor and put in it:
PushLayer(new GameLayer());
Now if you build the project, and run the launcher with -game TestGame
, it should work.
Your GameApp.cs file should look like:
public class GameLayer : ILayer
{
public void OnAttach()
{
}
public void OnDetach()
{
}
public void OnUpdate(TimeStep ts)
{
RenderingAPI.Clear();
RenderingAPI.SetClearColor(0, 0, 0);
}
public void OnEvent(IEvent e)
{
}
}
public class GameApp : Application
{
public GameApp()
{
PushLayer(new GameLayer());
}
}
You will need to copy the Texture.glsl
shader from the Sandbox app into yours. Make sure its in the Shaders/
directory. If you want to automatically copy files see the Copy files to game guide.