Monday, August 22, 2011

Code::Blocks(15) RPG 4 - An intro screen



<I will show how I did two things: the intro / splash screen and the outro, before starting I have to say that an intro screen is very important because it is like a business card: The sign from your game, obviously I'm not going to expend a week to make a 3D- synthesized intro but I will include it into the game so anybody can make their own, feel free to play with it>

<My intro probably is the easier one you can do, I just made an Image with the gimp "File" > "Create" > "Logo" > then I chosen a marble texture, replaced the text and voilá!:>

<Intro image, saved as "tittle.png">


<Then what I did was to make the background to fade in from black to white while I was showing the tittle image, to do so I just made a for loop with an integer variable "i" and filled the background with that value from {0,0,0} to {255,255,255}, finally I added a small delay (10ms) every frame to make it a little slower>

<"SplashScreen" method:>

void Game::SplashScreen() //Splash /Intro Screen
{

SDL_Surface* Tittle; //A surface to load intro image
Tittle = IMG_Load("images/tittle.png");
int i;
for (i=0;i<255;i++)
{
myengine.FillColour(i,i,i); //Will fill the background from color {0,0,0} (black) to {255.255.255} (white)
SDL_Rect end; //To set the intro image position
end.x = (myengine.ScreenX / 2) - (Tittle->w/2); // X
end.y = (myengine.ScreenY / 2) - (Tittle->h/2); // Y
end.w = Tittle->w;
end.h = Tittle->h;

SDL_BlitSurface(Tittle, NULL, myengine.screen, &end);//Blit the intro image

myengine.Flip();
SDL_Delay(10); // slow down the process so we will actually se something on screen

}//For

SDL_FreeSurface(Tittle);//Clean memory

myGameState = MENUSTART; //Go to start menu
}

<for the outro I just swapped the colour order from (0 to 255) in the intro to (255 to 0)  in the outro so it faded from white to black>

<"OutroScreen" method:>

void Game::OutroScreen()//Splash Screen
{

SDL_Surface* Tittle; //A surface to load outro image
Tittle = IMG_Load("images/tittle.png");
int i;
for (i=255;i>1;i--)//Will fill the background from color {255.255.255} (white) to {0,0,0} (black)
{
myengine.FillColour(i,i,i);
SDL_Rect end;
end.x = (myengine.ScreenX / 2) - (Tittle->w/2); // X
end.y = (myengine.ScreenY / 2) - (Tittle->h/2); // Y
end.w = Tittle->w;
end.h = Tittle->h;

SDL_BlitSurface(Tittle, NULL, myengine.screen, &end);
myengine.Flip();
SDL_Delay(10);// slow down the process so we will actually se something on screen

}//For

SDL_FreeSurface(Tittle);//Clean memory

myGameState = END; // It does not needs an explanation, right?
}

<In the next post: Game menus..>

No comments: