Skip to content
Yannick Comte edited this page Nov 10, 2017 · 2 revisions

C3DE basics

C3DE uses a scenegraph and scene manager. The idea is to create your scene in a C# file, add it to the engine and run your game.

A basic project

The first thing is to create two files for your two scenes. MenuScene.cs and GameScene.cs. In your main function, you can start the engine like that.

public static class Program
{
    static void Main(string[] args)
    {
        using (var game = new Engine("C3DE Demo Game", 1280, 800))
        {
            Application.SceneManager.Add(new MenuScene());
            Application.SceneManager.Add(new GameScene());
            Application.SceneManager.LoadLevel(0);
            game.Run();
        }
    }
}

This is basically what you have already done with XNA or MonoGame. The Engine class inherits from the Game class. At any time you can access this class using the static helper Application. The SceneManager allows you to add, remove and load scenes. In this example, we added two scenes and loaded the first one.

Your first scene

using C3DE.Components.Controllers;
using C3DE.Components.Lights;
using C3DE.Components.Renderers;
using C3DE.Geometries;
using C3DE.Materials;
using C3DE.Prefabs;
using C3DE.Utils;
using Microsoft.Xna.Framework;
using System;

public class MenuScene : Scene
{
    public MenuScene() : base("Menu demo") { }

    public override void Initialize()
    {
        base.Initialize();

        // Add a camera and add an orbit controller script on it.
        var cameraGo = GameObjectFactory.CreateCamera();
        Add(cameraGo);

        // Add a SpotLight
        var lightGo = GameObjectFactory.CreateLight(LightType.Point, colors[i], 1.5f, 1024);
        lightGo.Transform.Rotation = new Vector3(0.0f, 0.5f, 0);
        lightGo.Transform.Position = pos[i];
        Add(lightGo);

        // Terrain
        var terrainMaterial = new StandardMaterial(scene);
        terrainMaterial.MainTexture = GraphicsHelper.CreateBorderTexture(Color.CornflowerBlue, Color.Black, 128, 128, 2);
        terrainMaterial.Shininess = 150;
        terrainMaterial.Tiling = new Vector2(32);

        var terrainGo = GameObjectFactory.CreateTerrain();
        var terrain = terrainGo.GetComponent<Terrain>();
        terrain.Geometry.Size = new Vector3(4);
        terrain.Geometry.Build();
        terrain.Flatten();
        terrain.Renderer.Material = terrainMaterial;
        terrain.Renderer.ReceiveShadow = true;
        terrain.Renderer.CastShadow = false;
        terrainGo.Transform.Translate(-terrain.Width >> 1, 0, -terrain.Depth / 2);
        Add(terrainGo);

        // Create an empty GameObject with a Transform component
        var gameObject = new GameObject("My Game Object");
        Add(gameObject);

        // Generate a Skybox
        RenderSettings.Skybox.Generate();
    }
}

In this example we create a camera, a ground and its material as well as a spot light!