This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Плагины
Форматы файлов
Материалы и шейдеры
Rebuilding the Engine Tools
Интерфейс пользователя (GUI)
Двойная точность координат
API
Containers
Common Functionality
Controls-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Работа с контентом
Оптимизация контента
Материалы
Визуальный редактор материалов
Сэмплы материалов
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Учебные материалы
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Unigine::LoadingScreen Class

Header: #include <UnigineLoadingScreen.h>

A singleton that controls the settings of the loading screen. Demonstration of it gives UNIGINE the time to load all world nodes and resources. You can also show your own loading screen when needed.

A loading screen displays a texture that is usually divided into two parts stacked vertically — the initial and final pictures — which are gradually blended from the beginning up to the end of loading to show the progress. Blending is performed based on the alpha channel of the outro (lower) part of the texture so pseudo-animation can be created using the alpha channel: regions of the lower half with small alpha values will be shown first, regions with larger alpha values will be shown last.

See Also#

  • A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/widgets/ folder:

    • loading_screen_00
    • loading_screen_01
    • loading_screen_02
  • Quick Video Guide: How To Customize Loading Screens

Example

Here's a code example on how to add your own loading screens for application and world loading.

To show your loading screen on system logic initialization before a world is loaded, define it inside the init() method of the System Logic:

Source code (C++)
#include "AppSystemLogic.h"
#include "UnigineLoadingScreen.h"

using namespace Unigine;

int AppSystemLogic::init()
{
	

	// define new transform for loading screen texture
	Math::vec4 transform = Math::vec4(1.0f, 1.0f, 0.0f, 0.0f);

	// enable the loading screen
	LoadingScreen::setEnabled(true);

	// set transform to the loading screen texture
	LoadingScreen::setTransform(transform);

	Math::ivec2 winsize = WindowManager::getMainWindow()->getClientSize();
	// compute the aspect ratio to show the corresponding texture
	float aspect_ratio = (float)winsize.x / (float)winsize.y;

	// if the aspect ratio is 4:3 show the following loading screen
	// during world loading
	if (aspect_ratio < 1.5f) {
		LoadingScreen::setTexturePath("textures/splash_4x3.png");
	}
	else {
		// if the aspect ratio is 16:9 show this loading screen
		// during world loading
		LoadingScreen::setTexturePath("textures/splash_16x9.png");
	}
	// set the text to be displayed on the loading screen
	// with a certain displacement along the X and Y axes
	LoadingScreen::setText("<xy x=\"%50\" dx=\"0\" y=\"%50\" dy=\"0\"/>LOADING_PROGRESS");

	// set duration (in milliseconds) and display the loading screen on world loading
	float duration = 5000.0f;
	float begin = clock();

	while (clock() - begin < duration)
		LoadingScreen::render((clock() - begin) / duration * 100.0f);

	// disable the loading screen
	LoadingScreen::setEnabled(false);

	return 1;
}

A loading screen defined in the init() method of the World Logic will be shown right after a world is loaded:

Source code (C++)
#include "AppWorldLogic.h"
#include "UnigineLoadingScreen.h"

using namespace Unigine;

int AppWorldLogic::init()
{

	// enable the loading screen
	LoadingScreen::setEnabled(true);
	

	// set the text to be displayed on the loading screen,
	// specifying a color, a font, and a certain displacement along the X and Y axes
	LoadingScreen::setText("<p align=\"center\"><font size=\"20\" color=\"#FF0000FF\">CUSTOM LOADING TEXT</font></p>");

	// set duration (in milliseconds) and display the loading screen on world loading
	float duration = 5000.0f;
	float begin = clock();

	while (clock() - begin < duration)
		LoadingScreen::render((clock() - begin) / duration * 100.0f);

	// disable the loading screen
	LoadingScreen::setEnabled(false);

	return 1;
}

LoadingScreen Class

Members


void setEnabled ( bool enabled ) #

Specifies if manual rendering of the loading screen can be started or should be stopped.
Notice
setEnabled() is used only together with the corresponding render functions (render()). It cannot be used to enable or disable rendering of the loading screen during the initialization stage of the engine.

Arguments

  • bool enabled - true to enable manual rendering of a custom loading screen; false to disable.

bool isEnabled ( ) const#

Returns a value indicating if manual rendering of a loading screen is allowed.

Return value

true if the rendering of the loading screen is enabled; otherwise, false.

void setThreshold ( int threshold ) #

Sets the amount of blur in the alpha channel when interpolating between states of the loading screen.
Notice
By default, the Threshold value is set to 16.

Arguments

  • int threshold - amount of blur in the [0, 255] range.

int getThreshold ( ) const#

Returns the amount of blur in the alpha channel when interpolating between states of the loading screen.

Return value

amount of blur.

void setTexturePath ( const char * path ) #

Sets the path to a texture for custom loading screens.

Arguments

  • const char * path - Path to a file with the custom loading screen texture. If NULL (0) is passed, no texture will be used.

const char * getTexturePath ( ) const#

Returns the path to the texture for loading screens.

Return value

Path to the texture of the loading screens.

void setImage ( const Ptr<Image> & image ) #

Sets an image for a custom loading screen.

Arguments

  • const Ptr<Image> & image - Image smart pointer to an image to be used as a custom loading screen.

void getImage ( const Ptr<Image> & image ) const#

Returns the current image for a custom loading screen.

Arguments

  • const Ptr<Image> & image - Image used as a custom loading screen.

void setTransform ( const Math::vec4 & transform ) #

Sets transformation of the loading screen texture.

Arguments

  • const Math::vec4 & transform - Transformation of the loading screen texture:
    1. Texture size multiplier.
    2. Window size multiplier.
    3. Horizontal position in the [0.0f, 1.0f] range.
    4. Vertical position in the [0.0f, 1.0f] range.

Math::vec4 getTransform ( ) const#

Returns transformation of the loading screen texture.

Return value

transformation of the texture.

void setBackgroundColor ( const Math::vec4 & color ) #

Sets the background color of the loading screen.

Arguments

  • const Math::vec4 & color - Background color.

Math::vec4 getBackgroundColor ( ) const#

Returns the background color of loading screens.

Return value

Background color.

void setText ( const char * text ) #

Sets the text of the loading screen.

Arguments

  • const char * text - Text of the loading screen. Can be either a plain or rich text. A number of aliases is available:
    • UNIGINE_COPYRIGHT — the UNIGINE copyright text.
    • UNIGINE_VERSION — the current UNIGINE version.
    • LOADING_PROGRESS — the loading progress going from 0 to 100.
    • LOADING_WORLD — the world being loaded (if any).

const char * getText ( ) const#

Returns the text of the loading screen.

Return value

Text of the loading screen.

void setFontPath ( const char * path ) #

Sets the path to the font used to render the text.

Arguments

  • const char * path - Path to the font (True Type Font).

const char * getFontPath ( ) const#

Returns the path to the font used to render the text.

Return value

Path to the font.

void renderInterface ( ) #

Renders a static loading screen. Such a screen does not display any progress.

void render ( ) #

Renders the loading screen in the current progress state and with the current stage message.

void render ( int progress ) #

Renders a custom loading screen in a given progress state. Use this function in a loop to create a gradual change between the initial (upper opaque part) and the final states (bottom transparent part) of the loading screen texture.

Arguments

  • int progress - Progress of alpha blending between 2 screens stored in the texture. The value in range [0;100] sets an alpha channel threshold, according to which pixels from the initial (opaque) or final (transparent) screen in the texture are rendered. By the value of 0, the initial screen is loaded. By the value of 100, the final screen is loaded.

void render ( int progress, const char * message ) #

Renders a custom loading screen in a given progress state and prints a given message. Use this function in a loop to create a gradual change between the initial (upper opaque part) and the final states (bottom transparent part) of the loading screen texture, while printing a custom loading stage.

Arguments

  • int progress - Progress of alpha blending between 2 loading screens stored in the texture. The value in range [0;100] sets an alpha channel threshold, according to which pixels from the initial (opaque) or final (transparent) loading screen in the texture are rendered. By the value of 0, the initial screen is loaded. By the value of 100, the final screen is loaded.
  • const char * message - message to print representing the loading stage.

void renderForce ( ) #

Renders the loading screen regardless of whether the manual rendering is allowed or not.

void renderForce ( const char * message ) #

Renders the loading screen regardless of whether the manual rendering is allowed or not and prints a given message.

Arguments

  • const char * message - message to print that represents the loading stage.

int getProgress ( ) const#

Returns the current progress state.

Return value

Progress state in the [0, 100] range.

const char * getMessage ( ) const#

Returns the text message representing the current loading stage.

Return value

Loading message.

void * addRenderBeginCallback ( Unigine::CallbackBase * func ) #

Adds a callback function that will be executed when rendering of the loading screen begins. The function is useful when you implement a custom loading screen rendering function, for example. The callback function must not take arguments.
Source code (C++)
// the callback function
void AppWorldLogic::render_begin_callback()
{
	/* .. */
}

int AppWorldLogic::init()
{
	// set the callback
	void * id = LoadingScreen::addRenderBeginCallback(MakeCallback(this,&AppWorldLogic::render_begin_callback));
	
	return 1;
}

Arguments

  • Unigine::CallbackBase * func - The pointer to the callback with no arguments.

Return value

ID of the last added callback of the specified type, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool removeRenderBeginCallback ( void * id ) #

Removes the specified callback from the list of render begin callbacks.

Arguments

  • void * id - Callback ID obtained when adding it.

Return value

True if the callback with the given ID was removed successfully; otherwise false.

void clearRenderBeginCallbacks ( ) #

Clears all added render begin callbacks.

void * addRenderEndCallback ( Unigine::CallbackBase * func ) #

Adds a callback function that will be executed when rendering of the loading screen ends. The function is useful when you implement a custom loading screen rendering function, for example. The callback function must not take arguments.
Source code (C++)
// the callback function
void AppWorldLogic::render_end_callback()
{
	/* .. */
}

int AppWorldLogic::init()
{
	// set the callback
	void * id = LoadingScreen::addRenderEndCallback(MakeCallback(this,&AppWorldLogic::render_end_callback));
	
	return 1;
}

Arguments

  • Unigine::CallbackBase * func - The pointer to the callback with no arguments.

Return value

ID of the last added callback of the specified type, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool removeRenderEndCallback ( void * id ) #

Removes the specified callback from the list of render end callbacks.

Arguments

  • void * id - Callback ID obtained when adding it.

Return value

True if the callback with the given ID was removed successfully; otherwise false.

void clearRenderEndCallbacks ( ) #

Clears all added render end callbacks.

void setMessageLoadingWorld ( const char * world ) #

Sets a message to be displayed on world loading.

Arguments

  • const char * world - Message on world loading. The text aliases are also supported.

const char * getMessageLoadingWorld ( ) const#

Returns the current message displayed on world loading.

Return value

Message on world loading.

void setMessageShadersCompilation ( const char * compilation ) #

Sets a message to be displayed on shaders compilation.

Arguments

  • const char * compilation - Message on shaders compilation. The text aliases are also supported.

const char * getMessageShadersCompilation ( ) const#

Returns the current message displayed on shaders compilation.

Return value

Message on shaders compilation.
Last update: 23.06.2023
Build: ()