A New Game
Learn how to create a new game with the Kakara Engine.
Now that the engine is installed and ready to go, we can begin coding a game.
Main Game Class
To start off with we need to create a new class that represents the main class for our game. It is normal for us to call this class the name of the game. In this example it will be KakaraExample
. This class needs to implement the Game interface.
No graphics can be used in this class. This class is meant for cross scene functionality.
This class allows you to control the behavior of the game through out the game's runtime.
Start Method
The start method is called when the game first starts. As the warning about states, nothing involving graphics can be called in this method.
This method is best used for storing an instance of the GameHandler.
Update Method
The update method is called every frame. It is meant for cross scene functionality. We will not do anything with this update method in our tutorial.
Exit Method
This method is called when the game is terminated by the user. This could be triggered by the user closing the window, killing the game in Task Manager, or the use of gameHandler.exit(). The GameHandler provides us with the ability to exit the game peacefully, so closing the game that way is recommended.
All of the Engine's systems have been cleaned up by the time this method has been called. It is not safe to call any of the Engine's methods.
Game Scene
The engine operates using a Scene (level) system. Scenes contain all data related to game items, lighting, models, etc. There must be an active scene at all times, so we must create a scene for our game. For now we will have the main game scene be the default scene. In the future we will go back and make a title scene.
To begin we need to create a new class called MainScene
. That class will act as the scene our game will function in. MainScene
then needs to extend AbstractGameScene.
Work Method
Graphics cannot be initialized in this method. Use the loadGraphics method instead.
This method is called before the initialization of the render system. In our tutorial we will leave this method blank.
Load Graphics Method
This is the important method of every scene class. This is where the graphics of the game are created. Textures, Game Items, Meshes, and UI Elements, are created in this method for the scene. For now we will leave this method blank so we can create an empty window.
Update Method
This method is called every frame for the game. Any code that needs to execute every frame that is not item specific is ran here. Code that is item specific (like player movement) is done through the Component system. We will also leave this method blank for now.
Settings the Default Scene
Now that we have our main scene created we need to tell the engine to use that scene by default. We do that by going back to our KakaraExample
class and changing the firstScene()
method to return an instance of our scene.
The Main Method
Now it is time to create the class that contains the Main method for the engine. We will put our main method in a new class called Main
In the code above we are creating an instance of our KakaraExample
class. We then construct the main game engine class with its parameters.
The first parameter is the title of the game. The second and third parameter are the width and height of the window respectively. The fourth parameter is if you want vsync enabled. The last parameter is the instance of your class that implements the Game interface.
Finally, the game is ran via gameEngine.run();
.
Now when you run the code you should see the following pop up:
Debugging Problems
If you experience any issue be sure to check out the section on debugging. That section will tell you how to enable engine logs so you can figure out the problem.
Final Code
Last updated