Welcome to this informative page, where you’ll be guided through the initial steps on the fascinating journey of crafting your very own game using GFX.
To be able to use the engine optimally, it is first necessary to download it. This is a straightforward process where you just need to select the latest release on Github. By taking this step, you not only secure access to the latest version of GFX, but also to numerous improvements, bug fixes and new features that are continuously provided by our dedicated development team.
After you have successfully downloaded the latest version of GFX and added the project template to your Visual Studio, we will create a new project from these files and add the Genesis.dll as a reference to this project. Please make sure you run the build within the x64 settings.
Create your game
This code is intended to help you understand how the game engine works. The basic principle is quite simple: you have a base class called “Game”, which contains various scenes.
A scene is basically a class in itself. It contains different layers for game elements and can have multiple canvases for user interface elements. As mentioned above, the layers contain game elements such as entities, sprites or 3D models. These elements can be equipped with various scripts, so-called “GameBehaviors”. There are already predefined behaviours, or you can create your own.
For more complex games, it is also possible to inherit directly from the Scene class. This allows you to bring more structure to your project and improve the organisation.
Example Code
C#
usingGenesis.Core;usingGenesis.Graphics.RenderDevice;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingGenesis.Math;usingGenesis.Core.GameElements;usingGenesis.Physics;usingGenesis.Core.Behaviors.Physics2D;usingGenesis.Graphics.Physics;usingSystem.Management.Instrumentation;usingGenesis.Core.Behaviors;usingGenesis.Graphics;namespacePhysics2DTest{publicpartialclassForm1 : Form { // Game instance for managing the game loop and scenesprivateGamem_game; // Constructor for the main formpublicForm1() {InitializeComponent(); // Initialize the game and set up rendering and viewport m_game =newGame(newGLRenderer(this.Handle), newGenesis.Graphics.Viewport(this.ClientSize.Width, this.ClientSize.Height)); m_game.TargetFPS =60; m_game.AssetManager.LoadTextures(); // Create a test scenevartestScene=newScene("TestScene"); // Set up the camera for the test scene testScene.Camera =newGenesis.Graphics.Camera(newGenesis.Math.Vec3(0f, 0f), newGenesis.Math.Vec3(this.ClientSize.Width, this.ClientSize.Height), -10, 10); testScene.AddLayer("BaseLayer"); // Set up the physics handler for the scenevarphysicsHandler=newPhysicsHandler2D(0f, -10f); testScene.PhysicHandler = physicsHandler; // Create a player sprite with physics and animation behaviorvarplayer=newSprite("Player", newVec3(-300, 0), newVec3(32, 32), m_game.AssetManager.GetTexture("player.png"));varanimationBehavior= player.AddBehavior<AnimationBehavior>(newAnimationBehavior(5, 3, 100, m_game.AssetManager.GetTexture("CharacterAnimations.png")));varwalkRight=newAnimation("MoveRight", 0, 0, 5); animationBehavior.AddAnimation(walkRight);varwalkLeft=newAnimation("MoveLeft", 0, 1, 5); animationBehavior.AddAnimation(walkLeft);varidle=newAnimation("Idle", 0, 2, 5); animationBehavior.AddAnimation(idle); animationBehavior.SelectedAnimation = idle;varphysicsBehavior= player.AddBehavior(newRigidbody2D()); physicsBehavior.CreateRigidbody(testScene.PhysicHandler, 1f); physicsBehavior.RigidBody.AngularFactor =newVec3(0f, 0f, 0f).ToBulletVec3(); testScene.AddGameElement("BaseLayer", player); // Event handler for sprite collision physicsBehavior.OnCollide += (scene, game, collisionObject) => {foreach(GameElementelementin scene.GetLayer("BaseLayer").Elements) {Rigidbody2Drigidbody2D= (Rigidbody2D) element.GetBehavior<Rigidbody2D>();if(rigidbody2D !=null) {if(rigidbody2D.RigidBody == collisionObject) { Console.WriteLine("Collision with "+ rigidbody2D.Parent.Name); } } } }; // Create and add several block sprites to the scenevarspacing=120f;for (inti=0; i <5; i++) {varx=-300+ ((64.0f* i) + i * spacing);varcolObject=newSprite("ColObject_"+ i, newVec3(x, -150), newVec3(64, 64), m_game.AssetManager.GetTexture("block.png"));varcolPhysicsBehavior= colObject.AddBehavior(newRigidbody2D()); colPhysicsBehavior.CreateRigidbody(testScene.PhysicHandler, 0f); testScene.AddGameElement("BaseLayer", colObject); } // Event handler for game initialization m_game.OnInit += (game, renderer) => { animationBehavior.Play();PhysicsHandler2DphysicsHandler2D= (PhysicsHandler2D)testScene.PhysicHandler; physicsHandler2D.PhysicsWorld.DebugDrawer =newBulletDebugRenderer(m_game.RenderDevice); }; // Event handler for rendering the debug information m_game.OnRenderEnd += (game, renderer) => {PhysicsHandler2DphysicsHandler2D= (PhysicsHandler2D)testScene.PhysicHandler; physicsHandler2D.PhysicsWorld.DebugDrawWorld(); Console.WriteLine(m_game.FPS); }; // Event handler for player movement based on keyboard input m_game.OnUpdate += (game, renderer) => {floatjumpSpeed= (float)game.DeltaTime *0.3f;floatmoveSpeed= (float)game.DeltaTime *0.3f;if (Input.IsKeyDown(Keys.Space)) { player.Location.Y += jumpSpeed; physicsBehavior.UpdateRigidBody(); }if (Input.IsKeyDown(Keys.A)) { player.Location.X -= moveSpeed; physicsBehavior.UpdateRigidBody();if (!animationBehavior.SelectedAnimation.Name.Equals("MoveLeft")) { animationBehavior.LoadAnimation("MoveLeft"); } animationBehavior.Play(); }elseif (Input.IsKeyDown(Keys.D)) { player.Location.X += moveSpeed; physicsBehavior.UpdateRigidBody();if (!animationBehavior.SelectedAnimation.Name.Equals("MoveRight")) { animationBehavior.LoadAnimation("MoveRight"); } animationBehavior.Play(); }else { animationBehavior.Stop(); } testScene.Camera.LookAt(player); }; // Add the test scene to the game, load the scene, and start the game loop m_game.AddScene(testScene); m_game.LoadScene("TestScene"); m_game.Start(); } // Placeholder method for form load eventprivatevoidForm1_Load(objectsender, EventArgse) { } }}
Get the example project
To further enhance your understanding, you also have the option to download a sample project directly from our Github page. This example project serves as a practical demonstration, providing hands-on experience with the concepts discussed. By exploring the code, structure, and functionalities of the example project, you can gain a more tangible grasp of how the Game Engine operates.