Skip to content
enbacode edited this page Oct 22, 2014 · 2 revisions

After you installed Sharpex2D, you need to do some preconfiguring to get started.

Creating the Game Class

Open up your previously created Windows Forms Project, remove the default "Form1.cs", as we won't need it, and create a new class. For this tutorial, we'll call it "MainGame". Open up your class and include the Sharpex2D main namespace by adding using Sharpex2D; to the using directives on top of the file. Now let your "MainGame" class inherit from "Game" class of that namespace and implement all abstract class members. Your file should look like this:

using Sharpex2D;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SGLTest
{
    class MainGame : Game
    {
        public override EngineConfiguration OnInitialize(Sharpex2D.GameService.LaunchParameters launchParameters)
        {
            
        }

        public override void OnLoadContent()
        {
            
        }
    }
}

Explanation:

  • The OnInitialize method must return an EngineConfiguration which defines what services Sharpex2D should use for rendering and playing sound.
  • OnLoadContent is the place to use for any resources to be loaded. This can be sprites, sounds, fonts etc.

Engine Configuration

Go to the OnInitialize function and create a new EngineConfiguration object. The constructor requires at least a GraphicsManager object. GraphicsManager objects are responsible for providing an interface between Sharpex2D and your favourite graphics framework (such as OpenGL or DirectX).

For now, we'll keep it simple and use Sharpex2D's build-in OpenGL GraphicsManager. If you want to use different graphics frameworks (such as DirectX11), head over to Adding external Rendering Services. You'll find it in the Sharpex2D.Rendering.OpenGL namespace, so either include that namespace or write out the full namespace path to create a new OpenGLGraphicsManager object.

The EngineConfiguration constructor takes a SoundInitializer object as optional second parameter. For now, we'll ignore that one. If you want to play sounds, have a look at Playing Sounds.

Return your newly created EngineConfiguration object and proceed with the next step. Your OnInitialize function should look something like this:

public override EngineConfiguration OnInitialize(Sharpex2D.GameService.LaunchParameters launchParameters)
{
    return new EngineConfiguration(new OpenGLGraphicsManager());
}

Firing it

The last thing we have to do to get a compiling Sharpex2D project is telling Sharpex2D to start up. We'll do that as following:

  • Open the Program.cs file
  • Include Sharpex2D namespace
  • Replace Application.Run(new Form1()); with SGL.Initialize();

Press F5 and you should get a beautiful, cornflower blue window:

Initial window

Clone this wiki locally