Create company logo/sound for entry to application....

A forum to store posts deemed exceptionally wise and useful
Post Reply
Systemerror
Posts: 98
Joined: Fri Oct 03, 2008 1:25 pm
Location: UK
Contact:

Create company logo/sound for entry to application....

Post by Systemerror »

I thought some of you may appreciate this, as part of my Game Logic engine I wanted to think of a way to render my company logo, play intro sound and then go to menu state, whilst it may seem very simple it was rather complex to think of the best way to implement it; anyway, enough talk - the code is self explanitary and commented and is an example of how you can do this (note, this is a basic example you can improve upon it as much as you like):


LogoScene.h

Code: Select all

/*
Everything is declared and defined
for Logo scene as it is simple and small
and thus deemed pointless giving it an
implementation file
*/

#ifndef LOGO_H // header guard
 #define LOGO_H 

#include <irrlicht.h>
#include <irrKlang.h>

class LogoScene 
{
protected:

//for sound declaration used in both methods
irrklang::ISound* snd;
//temp int  for both methods
int introSceneCount;

public:
  void createIntroScene()
 {


	       device->setWindowCaption(L"Displaying company logo and playing music");
           //play a sound, with params no loop and tracking enabled
		   snd = engine->play2D("THE SOUND FILE",false,false,true);
	       //create Logo Image
		   irr::gui::IGUIImage* img = env->addImage(driver->getTexture("COMPANY IMAGE")
		   ,irr::core::position2d<irr::s32>(0,10));
           //disable mouse visibillity
		   device->getCursorControl()->setVisible(false);
   
  
}





//used to check if the sound is finished [to be used in main render loop]
void checkIntroSceneFinishParams()
{
	
	//used as a reference counter
	                             
		/*
        Wait for logo rendering/music
		to finish and then call the menu state
		*/
		   if(snd->isFinished() && introSceneCount == 0)
		   {	

                    env->clear();
			    device->getCursorControl()->setVisible(true);
			//Code for menu state here
				
              //break loop condition so loop is executed 1 time
		   introSceneCount = 1;
		   
		   
		   
		   }

}



}Logo;

#endif 

main.cpp

Code: Select all


//Other includes
#include <iostream>
#include "LogoScene.h"


#pragma comment(lib, "Irrlicht.lib") //link with irrlicht.dll
#pragma comment(lib, "irrKlang.lib") // link with irrKlang.dll




              //----remove console if desireable----
//#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")



//********************main****************

int main()
{  
std::cout<<"Initializing essentials...\n";


	   //create rendering device
	   device =  irr::createDevice( irr::video::EDT_DIRECT3D9, 
	   irr::core::dimension2d<irr::s32>(800, 600), 32, false ,true,false,0); 
	   //check if rendering device created
	    if(!device)
	     {
			 std::cout<<"Could not create device"<<std::endl;
			 return false;
	     }
		 
       //create irrklang engine init
	   engine = irrklang::createIrrKlangDevice();
	   //check if engine device was initialized
	    if(!engine)
		 {
			 std::cout<<"Could not initialize IrrKlang device"<<std::endl;
             return false;
		 }

	   
      //get driver
	  driver = device->getVideoDriver();
      //check if driver was retrieved
	    if(!driver)
		 {
			 std::cout<<"Could not locate driver"<<std::endl;
			 return false;
		 }

	
	   //get scene manager
       smgr = device->getSceneManager();
	   //check if smgr was retrieved
	     if(!smgr)
	      {
			  std::cout<<"Could not retrieve Scene Manager"<<std::endl;
			 return false;
	      }
      
	   //get GUI environment
	   env = device->getGUIEnvironment();
	   //check env was retrieved
	     if(!env)
		 {
			 std::cout<<"Could not get GUIEnvironment"<<std::endl;
			 return false;
		 }
       std::cout<<"Everything initialized\n";


   
  
    ///////////////////////create logo screen//////////////////////
   Logo.createIntroScene();


   
   
   while(device->run() && driver)
	{ 	
     //////////////check logo scene finish parameters///////////////////
		Logo.checkIntroSceneFinishParams();

		driver->beginScene(true, true, irr::video::SColor(255,120,120,120));
          
		smgr->drawAll();
		env->drawAll();
		driver->endScene();
		
	}
         device->drop();
         engine->drop();	
      return 0;
  }
-System error
kingdutch
Posts: 76
Joined: Tue Sep 02, 2008 7:01 am

Post by kingdutch »

Hey looks really nice, I might use this sooner or later (If you don't mind).

May I try to give a few optimisation suggestions (Don't know if they really are optimisations and it might not matter too much as I haven't done irlicht in way too long but who knows)

Let checkIntroSceneFinishParams() return either 1 or 0 depending on wether it's done, or not. Then in your first while loop just wait for it to be done, and then start your main program logic in a new while loop. While creating extra lines it will stop from checking the sound in each menu/game/program loop after the intro. :)

Good job :D
if (msg.getRubbishFactor() > rubbishLimit) { ignorePost(); cout << how it should be done << "\n"; }
Post Reply