-
Notifications
You must be signed in to change notification settings - Fork 9
Preconfiguring
After you installed Sharpex2D, you need to do some preconfiguring to get started.
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
OnInitializemethod must return anEngineConfigurationwhich defines what services Sharpex2D should use for rendering and playing sound. -
OnLoadContentis the place to use for any resources to be loaded. This can be sprites, sounds, fonts etc.
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());
}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.csfile - Include
Sharpex2Dnamespace - Replace
Application.Run(new Form1());withSGL.Initialize();
Press F5 and you should get a beautiful, cornflower blue window:
