Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Getting Started

Ollie Robinson edited this page Sep 4, 2022 · 5 revisions

Let's write our first program with Cubic!

In this guide, you will learn how to and create a basic program with Cubic.

Adding Cubic to your project

If you are already familiar with adding stuff to your project, feel free to skip this chapter.

If you haven't downloaded Cubic already, there are two ways to get it.

  • Directly download the ZIP, and extract it.
  • Install git and run git clone https://github.com/piegfx/Cubic.git in your chosen folder (for example a folder called Programming).

Let's add it to our project!

Using git

If your project doesn't have a solution, type dotnet new sln to add one to your project.

Now type dotnet sln add <cubic location>/Cubic, where the cubic location is wherever you extracted the cubic folder to. In our case, it's just ../Cubic. The reason you need to add the /Cubic to the end is because the project file itself is located within the Cubic subdirectory.

Finally, we need to add a reference. Type dotnet add reference <cubic location>/Cubic, where the cubic location is the same location as you entered before.

If there are no errors, you've successfully added Cubic to your project!

Writing your first program

At the end of this chapter you will have a simple black window.

To create a basic window, all you need is the following code:

using Cubic.Windowing;

GameSettings settings = new GameSettings();

using CubicGame game = new CubicGame(settings);
game.Run();

That's seriously all you need. ....Almost. Try running it, don't worry, it won't bite.

You may have noticed that an exception has been thrown, complaining about scene stuff. This is because Cubic always requires at least one scene to be present in your game for it to start. So let's create one!

Create a new class called MyScene, and add using Cubic.Scenes; to the top. Finally, just derive off the Scene class. Your file should look like this:

using Cubic.Scenes;

namespace MyFirstCubicApp;

public class MyScene : Scene
{

}

Next, let's add it to our game.

Back in our Program.cs file, import two new namespaces: using Cubic.Scenes; and using MyFirstCubicApp; (or whatever your project is called).

Next, you need to add the scene to the SceneManager, like such:

SceneManager.RegisterScene<MyScene>("my scene");

Make sure you do this before you call game.Run(), and personally I like to place it just after I call using CubicGame game ..., although it doesn't actually matter.

So finally, our file should look like this:

using Cubic.Windowing;
using Cubic.Scenes;
using MyFirstCubicApp;

GameSettings settings = new GameSettings();

using CubicGame game = new CubicGame(settings);
SceneManager.RegisterScene<MyScene>("my scene");
game.Run();

If you run it, you should get a blank window without any errors! Awesome stuff!

Cubic Window

Try fiddling around with some stuff, adjust some of the default GameSettings, or, just move onto the next tutorial.

Clone this wiki locally