Getting some credit

Everyone likes to get credit for their hard work! Most games will implement a credits screen that shows the name and function of each person involved in creating the game. For AAA titles, this list may be as long as a list for a movie. For smaller, independent games, this list might be three people.

Creating the credits screen

Similarly to the main menu, the credits screen will be based on a background image and a button that can be clicked. We will also need to add text to the screen.

Let's start by declaring a pointer for our screen. Add the following declaration to the variables section of RoboRacer2D.cpp:

Sprite* creditsScreen;

Then, we will instantiate the credits screen in LoadTextures:

creditsScreen = new Sprite(1);
creditsScreen->SetFrameSize(800.0f, 600.0f);
creditsScreen->SetNumberOfFrames(1);
creditsScreen->AddTexture("resources/credits.png", false);
creditsScreen->IsActive(false);
creditsScreen->IsVisible(true);

Next, we wire the credits screen into Update:

 case GameState::GS_Credits:
 {
  creditsScreen->Update(p_deltaTime);
  inputManager->Update(p_deltaTime);
  ProcessInput(p_deltaTime);
 }
 break;

We also update Render:

 case GameState::GS_Credits:
 {
  creditsScreen->Render();
 }
 break;

Getting back to the main menu

We now need to add a button that allows us to get from the credits screen back to the main menu. We first declare the pointer in the variables declaration section:

Sprite* menuButton;

We then instantiate the button in LoadTextures:

menuButton = new Sprite(1);
menuButton->SetFrameSize(75.0f, 38.0f);
menuButton->SetNumberOfFrames(1);
menuButton->SetPosition(390.0f, 400.0f);
menuButton->AddTexture("resources/menuButton.png");
menuButton->IsVisible(true);
menuButton->IsActive(false);
inputManager->AddUiElement(menuButton);

Let's add the button to Update:

case GameState::GS_Credits:
 {
  creditsScreen->Update(p_deltaTime);
  menuButton->IsActive(true);
  menuButton->Update(p_deltaTime);
  inputManager->Update(p_deltaTime);
  ProcessInput(p_deltaTime);
 }
 break;

We also update Render:

 case GameState::GS_Credits:
 {
  creditsScreen->Render();
  menuButton->Render();
 }
 break;

Similarly to the menu buttons, we now need to add code to the case Input::Command::CM_UI: case in ProcessInput to handle clicking on the menu button:

if (menuButton->IsClicked())
{
  menuButton->IsClicked(false);
  menuButton->IsActive(false);
  m_gameState = GameState::GS_Menu;
}

When the menu button is clicked, we change the game state back to menu, and set the menu button to be inactive. Due to the code that we have already written, the menu screen will automatically display.

Getting back to the main menu
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.10.69