In this example we are going to see how to create a game interface using C++ and Maratis SDK.
We will use the SimpleGamePlugin Demo as a base project, and simply customize the Game class (MyGame.h and MyGame.cpp).
The main idea is to draw a scene with a life bar and a mouse cursor (the GUI scene) on top of one other (the current scene) :
1 : Project creation :
In a new Level create 2 Scenes :
- Scene-1 will be the game scene :
Here some boxes with a perspective camera and a spot light with dynamic shadows
- GUIScene will be the interface scene :
Meshs are done in Blender with a simple textured quad, the blending mode of the Material is « Alpha blending ».
In Maratis, the GUI objects are oriented in X and Y, to be in the same space as the mouse coordinates. To arrange easily the scene in 2d, select the « Bottom » view.
Create a camera oriented toward Z. Then, in the camera properties, select « Ortho » to activate the orthographic projection (2d).
2 : Game plugin creation
We are now going to create a game plugin derived from the SimpleGamePlugin Demo.
- We will modify the game class to draw one scene on top of the other and to move the cursor object according to the mouse position.
Let’s first enable the following functions of the Game class in MyGame.h :
And write the code in MyGame.cpp :
These functions are virtual, if they are not customized, they are executing the standard Maratis code. In this example, we want to draw the current scene normally and just draw another scene on top.