Enable a simple splash screen displayed during loading time.
LUA
In LuaScripts/Utilities/Sample.lua:
Add this line at the beginning of SampleStart() function:
SplashScreen() -- Display splash screen
Then create new functions:
function SplashScreen()
local splashUI = ui.root:CreateChild("BorderImage", "Splash")
local texture = cache:GetResource("Texture2D", "Textures/LogoLarge.png") -- Get texture
splashUI.texture = texture -- Set texture
splashUI:SetSize(texture.width, texture.height)
splashUI:SetAlignment(HA_CENTER, VA_CENTER)
engine:RunFrame() -- Render Splash immediately
SubscribeToEvent("EndRendering", "HandleSplash") -- Keep visible until rendering of the scene
end
function HandleSplash(eventType, eventData)
-- Remove splash screen when the scene gets rendered
if ui.root:GetChild("Splash") ~= nil then ui.root:GetChild("Splash"):Remove() end
UnsubscribeFromEvent("EndRendering")
end
ANGEL SCRIPT
In Scripts/Utilities/Sample.as:
Add this line at the beginning of SampleStart() function:
SplashScreen();
Then create new functions:
void SplashScreen()
{
BorderImage@ splashUI = ui.root.CreateChild("BorderImage", "Splash");
Texture2D@ texture = cache.GetResource("Texture2D", "Textures/LogoLarge.png"); // Get texture
splashUI.texture = texture; // Set texture
splashUI.SetSize(texture.width, texture.height);
splashUI.SetAlignment(HA_CENTER, VA_CENTER);
engine.RunFrame(); // Render Splash immediately
SubscribeToEvent("EndRendering", "HandleSplash"); // Keep visible until rendering of the scene
}
void HandleSplash(StringHash eventType, VariantMap& eventData)
{
// Remove splash screen when the scene gets rendered
if (ui.root.GetChild("Splash") !is null)
ui.root.GetChild("Splash").Remove();
UnsubscribeFromEvent("EndRendering");
}
C++
In Source/Samples/Sample.h
In namespace Urho3D, add:
class BorderImage;
Add to private:
void SplashScreen();
void HandleSplash(StringHash eventType, VariantMap& eventData);
In Source/Samples/Sample.inl:
Includes:
#include "BorderImage.h"
#include "GraphicsEvents.h"
Add this line at the beginning of void Sample::Start()
SplashScreen();
Then create new functions:
void Sample::SplashScreen()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
UI* ui = GetSubsystem<UI>();
BorderImage* splashUI = new BorderImage(context_);
splashUI->SetName("Splash");
Texture2D* texture = cache->GetResource<Texture2D>("Textures/LogoLarge.png");
splashUI->SetTexture(texture); // Set texture
splashUI->SetSize(texture->GetWidth(), texture->GetHeight());
splashUI->SetAlignment(HA_CENTER, VA_CENTER);
ui->GetRoot()->AddChild(splashUI);
GetSubsystem<Engine>()->RunFrame(); // Render Splash immediately
SubscribeToEvent(E_ENDRENDERING, HANDLER(Sample, HandleSplash)); // Keep visible until rendering of the scene
}
void Sample::HandleSplash(StringHash eventType, VariantMap& eventData)
{
// Remove splash screen when scene fully rendered
UIElement* splashUI = GetSubsystem<UI>()->GetRoot()->GetChild("Splash", true);
if (splashUI)
splashUI->Remove();
UnsubscribeFromEvent(E_ENDRENDERING);
}