Displaying a Splash Screen

From C4 Engine Wiki

Jump to: navigation, search
Image:warning.jpg Obsolete Article

Some or all of the information on this page is obsolete and needs to be updated.

Introduction

The recent C4 license requires that the "Powered By C4" logo be displayed at a width of at least 256 pixels. And if it is on a splash screen it is to be displayed for at least one second.

In this code, if a key is pressed while the splash screen is shown, it waits until a second has passed since the splash screen was first shown then exits the splash screen. After one second it spends the next four seconds fading out. Currently the splash screen can't detect mouse clicks.

The code

Edit MCGame.cpp:

Add "SplashScreen::Open();" "after MainWindow::Open();" in Game::Game()

SplashScreen::Open();

Edit MGInterface.cpp:

Add the following to the list of related statements:

SplashScreen *C4::TheSplashScreen = nullptr;

Add the following code:

LogoImageElement::LogoImageElement(float width, float height, const char *name) :
		ImageElement(width, height, name)
{
}
 
SplashScreen::SplashScreen() :
GameWindow(0.0F, 0.0F, nullptr, kWindowCenter | kWindowNoFrame),
		Singleton<SplashScreen>(TheSplashScreen)
{
	SetElementPosition(Point3D(0.0f, 0.0f, 0.0F));
	SetElementSize(TheDisplayMgr->GetDisplayWidth(), TheDisplayMgr->GetDisplayHeight());
 
	SetBackgroundColor(ColorRGBA(0.0f,0.0f,0.0f,1.0f));
 
	logoImage = new LogoImageElement(512, 256, "C4/logo");
	logoImage->SetElementPosition(Point3D((GetElementWidth() * 0.5f) - 256, (GetElementHeight() * 0.5f) - 128, 0.0F));
	logoImage->SetVertexTexcoord2D(0, Point2D(0.0F, 1.0F));
	logoImage->SetVertexTexcoord2D(1, Point2D(0.0F, 0.0F));
	logoImage->SetVertexTexcoord2D(2, Point2D(1.0F, 0.0F));
	logoImage->SetVertexTexcoord2D(3, Point2D(1.0F, 1.0F));
 
	AddSubnode(logoImage);
	SplashTime = 0;
	exitSplashScreen = false;
}
 
SplashScreen::~SplashScreen()
{
}
 
void SplashScreen::Open(void)
{
	if (TheSplashScreen) TheInterfaceMgr->SetActiveWindow(TheSplashScreen);
	else TheGame->AddWindow(new SplashScreen);
}
 
void SplashScreen::InterfaceTask(void)
{
	SplashTime += TheTimeMgr->GetDeltaTime();
 
	if (SplashTime > 1000) 
	{
		if (exitSplashScreen)
		{	
			delete this;
			return;
		}
		float alpha = (5000 - SplashTime) * 0.00025f;
		logoImage->SetQuadAlpha(alpha);
		SetBackgroundColor(ColorRGBA(0.0f, 0.0f, 0.0f, alpha));
	}
	if (SplashTime > 5000) delete this;
}
 
bool SplashScreen::HandleKeyboardEvent(EventType eventType, long key, unsigned long modifiers)
{
	exitSplashScreen = true;
	return true;
}

Add the following code to MGInterface.h

	class LogoImageElement : public ImageElement
	{
		public:
			LogoImageElement(float width, float height, const char *name);
	};
 
 
	class SplashScreen : public GameWindow, public Singleton<SplashScreen>
	{
		private:
			SplashScreen();
			LogoImageElement	*logoImage;
			bool exitSplashScreen;
		public:
 
			~SplashScreen();
 
			long SplashTime;
 
			static void Open(void);
 
			void InterfaceTask(void);
			bool HandleKeyboardEvent(EventType eventType, long key, unsigned long modifiers
	);
Personal tools