Handle Game Screens

Learn how to play with your game screens

Push Screens Onto The Screen-Stack

From the Engine Editor, you can create many Game Screens, However, those Game Screens are not directly available during your Game. In order to use a Screen, you have to explicitly activate it. This is done by pushing yours Screens onto the Screen-Stack also called the Screen Table. For example, if you create ten (10) Screens with the Editor and only push four (4), only the four will be available to be used.

  • Screen Order : The order in which you push Screens is important. Screens are drawn on top of each other, The first Screen to be pushed will be drawn below the next one and so on.
Once a Screen is pushed, you can remove it from the Screen-Stack by popping it. pushScreen and popScreen are two methods of the nero::Scene Calss.
//The Screen-Stack is LIFO table (Last In, First Out)
void pushScreen("screen_name"); //add a Screen on the Stack
void popScreen(); //remove the last Screen from the Stack
  • Example : From the Adventure Scene Demo
if(!isRenderEngine())
    return;
        
pushScreen(ScreenPool.game_screen);
pushScreen(ScreenPool.pause_screen);
pushScreen(ScreenPool.start_screen);
pushScreen(ScreenPool.options_screen);

Screens & Editor

In the code above (Example from adventure scene demo) you can remark this little chunk of code

if(!isRenderEngine())
    return;

This code is really important !. Game Screens can only be rendered or manipulated inside a Render Engine. They cannot be used inside the Editor (Dev Engine). Since your Scene can be running inside the Editor or a Render Engine you have to explicitly check that you are inside a Render Engine before to use or manipulate your Game Screens.

Show and Hide Screens

Once a Screen is on the Stack (and you Scene is running inside a Render Engine) you can make it visible or hide at any moment using the nero::Scene methods showScreen and hideScreen. When a screen becomes visible you can interact with it (click on buttons etc.)

void showScreen("screen_name"); //make a screen visible
void hideScreen("screen_name"); //make a screen invisible

Show and Hide Game World

Normally, Screens appear on top of the Game World, like a Pause Menu. What is you want the Screens to cover all the game windows, like a Start Menu or a Option Menu. In those cases you can simply make the entire Game World disappear and only display the you Screens. The nero::Scene offers two methods to do exactly that : showWorld and hideWorld.

void showWorld(); //make the Game World visible
void hideWorld(); //make the Game World invisible

Change The Canvas Color

Each Screen can has its own canvas color. You can retrieve that color with the nero::Scene class method getScreenCanvasColor(string), Then you can update you Scene canvas color with the nero::Scene class method setCanvasColor(sf::color).

//Scene Canvas color
sf::Color color = getCanvasColor(); //Retrieve you Scene current canvas color
setCanvasColor(color);  //Change your Scene canvas color
//Screen Canvas color
sf::Color color2 = getScreenCanvasColor("screen_name"); //Retrieve you Screen canvas color (the one set using the Editor)
//Example : update Scene Canvas color with screen one
setCanvasColor(getScreenCanvasColor("screen_name"));

Retrieve Screen Objects

The Object Manager offers two methods for retrieving the objects inside your Screens : findScreenObject and findScreenUIObject. The first method can only retrieve none ui-objects (Sprites, Animations, Texts) and the second can only retrieve ui-objects (Buttons).

//None UI Object
nero::Object::Ptr object = getObjectManager()->findScreenObject("screen_name", "object_name");
//UI Object
nero::Object::Ptr ui_object = getObjectManager()->findScreenUIObject("screen_name", "object_name"); 

Once a Object is retrieved you can convert it (cast it) to its original type.

//None UI Object
auto my_sprite = nero::SpriteObject::Cast(object);
auto my_animation = nero::AnimationObject::Cast(object);
auto my_text = nero::TextObject::Cast(object);
//UI Object
auto my_button = nero::ButtonObject::Cast(ui_object);

Check Screen Objects

As mentioned in  the tutorial Check Objects, it is important to check the existence of your Game World Objects very early. In addition to the method checkWorldObject, The Object Manager also offers the method checkScreenObject, which allows you to check your Screen Objects. The method takes the name of a Screen and a list of object names. Both methods checkWorldObject and checkScreenObject should be called manually inside your Scene method checkSceneObject.

//Template
getObjectManager()->checkScreenObject("screen_name", {"object_name_01, object_name_02, object_name_N"});

//Full example
void MyScene::checkSceneObject()
{
    //Start Screen
    getObjectManager()->checkScreenObject
    (
        ScreenPool.start_screen,
        {
            ButtonPool.startButton,
            ButtonPool.quitButton
        }
    );

    //Pause Screen
    getObjectManager()->checkScreenObject
    (
        ScreenPool.start_screen,
        {
            ButtonPool.resumeButton,
            ButtonPool.optionButton
        }
    );
}

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Nero Games will use the information you provide on this form to be in touch with you and to provide updates and marketing.