Startup Screen

Understand the Startup Screen Class

The Startup Screen Class

the class nero::StartupScreen provides you a simple way to create your own Startup Screen or Loading Screen. The class provides six (6) pure virtual methods that need to be overriden.

  • init() : Used to load your startup resources and build your screen initial state
  • handleEvent() : Used to handle keyboard or mouse events.
  • update() : Used for updating your screen state
  • render() : Used to render your screen
  • getBackgroundColor() : Used to specify the color you want for the background
  • getMinTime() : Used to specify how long you want the screen to last in seconds
////////////////////////////////////////////////////////////
// Nero Game Engine
// Copyright (c) 2016-2019 SANOU A. K. Landry
////////////////////////////////////////////////////////////
#ifndef STARTUPSCREEN_H
#define STARTUPSCREEN_H
///////////////////////////HEADERS//////////////////////////
//SFML
#include <SFML/Graphics/RenderWindow.hpp>
//STD
#include 
////////////////////////////////////////////////////////////
namespace nero
{
    class StartupScreen
    {
        public:
            typedef std::shared_ptr Ptr;

                                            StartupScreen();
            virtual                        ~StartupScreen();

            virtual void                    init()                                      = 0;
            virtual void                    handleEvent(sf::Event& event)               = 0;
            virtual void                    update(const sf::Time& timeStep)            = 0;
            virtual void                    render()                                    = 0;
            virtual const sf::Color         getBackgroundColor()    const               = 0;
            virtual const float             getMinTime()            const               = 0;
            void                            setRenderWindow(sf::RenderWindow* renderWindow);

        protected:
             sf::RenderWindow*              m_RenderWindow;
    };
}
#endif // STARTUPSCREEN_H

Create Your Own Startup Screen

When you want to create your own Startup Screen, you create a new class inheriting the class nero::StartupScreen, then you override all the six (6) pure virtual methods. The code below shows the most basic Startup Screen you can create. The Screen will display a white screen for five (5) seconds.

#include <Nero/engine/StartupScreen.hpp>

class MyStartupScreen : public nero::StartupScreen
{
	public:

	    void init()
	    {
	    	//do stuff
	    }

		void handleEvent(sf::Event& event)
		{
			//do stuff
		}
	    
	    void update(const sf::Time& timeStep)
	    {
			//do stuff    
	    }
	    
	    void render()
	    {
	    	//do stuff
	    }
	    
	    const sf::Color getBackgroundColor() const
	    {
	    	return sf::Color::White;
	    }

	    cnst float getMinTime() const
	    {
	    	return 5.f; //seconds
	    }
};

The Adventure Scene Loading Screen

The code below shows the Loading Screen of the Adventure Scene Example. You can use it as a template to create your own screen. The Screen has a white background and last 10 seconds. For the visual you have only three (3) textures. One texture for the text “Adventure Scene”, another texture for the airplane, both textures are simply displayed to the screen. The last texture is for the text “Loading …”, this texture has its opacity changing through time, giving a slow blinking effect.

////////////////////////////////////////////////////////////
// Project Adventure Scene
// Copyright (c) 2016-2020 SANOU A. K. Landry
////////////////////////////////////////////////////////////
#ifndef LOADINGSCREEN_H
#define LOADINGSCREEN_H
///////////////////////////HEADERS//////////////////////////
//NERO
#include <Nero/engine/StartupScreen.h>
#include <SFML/Graphics/Texture.hpp>
//SFML
#include <SFML/Graphics/Sprite.hpp>
////////////////////////////////////////////////////////////
namespace ng
{
    class LoadingScreen : public nero::StartupScreen
    {
        public:
            typedef std::shared_ptr<LoadingScreen> Ptr;

                                    LoadingScreen();

            void                    init();
            void                    handleEvent(sf::Event& event);
            void                    update(const sf::Time& timeStep);
            void                    render();

            const sf::Color         getBackgroundColor()    const;
            const float             getMinTime()            const;

        private:
            sf::Texture             mTitleTexture;
            sf::Sprite              mTitleSprite;

            sf::Texture             mLoadingTexture;
            sf::Sprite              mLoadingSprite;

            sf::Texture             mLogoTexture;
            sf::Sprite              mLogoSprite;

            float                   mTimeCount;
    };
}
#endif // LOADINGSCREEN_H
////////////////////////////////////////////////////////////
// Project Adventure Scene
// Copyright (c) 2016-2019 SANOU A. K. Landry
////////////////////////////////////////////////////////////
///////////////////////////HEADERS//////////////////////////
//Adventure Scene
#include "LoadingScreen.h"
//NERO
#include <Nero/utility/Utility.h>
////////////////////////////////////////////////////////////
namespace ng
{
    LoadingScreen::LoadingScreen(): nero::StartupScreen()
        ,mTimeCount(0)
    {

    }

    void LoadingScreen::init()
    {
        //The Textures(Images) for a Startup Screen should be located in the folder /startup
        //This folder is automatically created when the Engine start the first time

        //Build the title sprite
        mTitleTexture.loadFromFile(nero::STARTUP_FOLDER + "/adventure_scene.png");
        mTitleSprite.setTexture(mTitleTexture);
        nero::centerOrigin(mTitleSprite);
        mTitleSprite.setPosition(sf::Vector2f(m_RenderWindow->getSize().x / 2.f, 120.f));
        mTitleSprite.setScale(sf::Vector2f(1.1, 1.1f));
        //Build the logo sprite
        mLogoTexture.loadFromFile(nero::STARTUP_FOLDER + "/opp_aviator.png");
        mLogoSprite.setTexture(mLogoTexture);
        nero::centerOrigin(mLogoSprite);
        mLogoSprite.setPosition(sf::Vector2f(m_RenderWindow->getSize().x / 2.f, m_RenderWindow->getSize().y / 2.f));
        mLogoSprite.setScale(sf::Vector2f(1.5, 1.5f));
        //Build the loading sprite
        mLoadingTexture.loadFromFile(nero::STARTUP_FOLDER + "/loading.png");
        mLoadingSprite.setTexture(mLoadingTexture);
        nero::centerOrigin(mLoadingSprite);
        mLoadingSprite.setPosition(sf::Vector2f(m_RenderWindow->getSize().x / 2.f, 500.f));
    }

    void LoadingScreen::handleEvent(sf::Event& event)
    {
        //Empty
    }

    void LoadingScreen::update(const sf::Time& timeStep)
    {
        mTimeCount += timeStep.asSeconds();
        int alpha = std::abs(std::sin(mTimeCount))*255;
        mLoadingSprite.setColor(sf::Color(255, 255, 255, alpha));
    }

    void LoadingScreen::render()
    {
         m_RenderWindow->draw(mTitleSprite);
         m_RenderWindow->draw(mLogoSprite);
         m_RenderWindow->draw(mLoadingSprite);
    }

    const sf::Color LoadingScreen::getBackgroundColor() const
    {
        return sf::Color::White;
    }

    const float LoadingScreen::getMinTime() const
    {
        return 10.f; //second
    }
}

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.