Creating a WinMenu screen

To give the player feedback once they have won our game, we are going to create a WinMenu screen that will appear upon destroying the required number of targets. To create a menu, we are going to need another Blueprint widget, like what we developed for the HUD. Navigate to the UI folder we created and add a new Blueprint Widget, which is found under User Interface in the add menu. Name this Blueprint WinMenu.

We are going to set up three elements for this menu screen. The first will be a simple text object that broadcasts You Win! to the player. The other two elements will be buttons that allow the player to restart the game or quit it. To start with, drag two Button objects and one Text object onto CanvasPanel. Next, select the Text object and change its Text field to say You Win!. Change the font size to 72 and the font color to light green, and then resize and reposition the text object on the canvas so that it appears in the top-middle of the screen, but a little lower than where you placed your HUD objects in the previous chapter. Finally, anchor the object to the top-middle of the screen by selecting the second option from the Anchors selector.

Now, drag an additional Text object and place it on top of both Button objects. Rename the two Button objects as the Restart and Quit buttons. Change the size of the buttons so that they are roughly the same size as our You Win! textbox and stack them below the text display. Anchor both buttons to the center of the screen.

Next, select the Text object under the Restart button and change its Text field to Restart. Then, change the font size to 60. Change the font color to black to ensure it shows up on our gray buttons. Finally, click on the second button of both the Horizontal Alignment and Vertical Alignment settings. Do the same operations on the Text object attached to the Quit button, except that the Text field should display the text Quit:

Now, we need to add Actions that will fire when the buttons are pressed. Click on the Restart button object, scroll down to the bottom of the Details panel, and click on the + button next to the On Clicked Event. This will add an Event that triggers when the button is clicked.

You will be taken to the graph view, where an On Clicked (Restart) button node will appear. Attach an Open Level node to this. Type in the name of your Level into the Level Name field, ensuring the accuracy of spelling. If you've been following along and have not changed the name of Level from the template, then this will be FirstPersonExampleMap. Doing this will reopen the Level when the player clicks on the button, resetting all aspects of the Level, including targets, ammo collectibles, and the player.

After the Open Level node, attach a Remove from Parent node. This node tells our WinMenu objects to stop displaying. We want the menu to go away once the Level is reset.

Now, return to the designer view and click on the Quit button object. Click on the + button next to the On Clicked (Restart) Event here as well. You'll be taken back to the graph view, but this time, with a new On Clicked (Quit) button node. Attach a Quit Game node to this Event so that the player can shut down the game by clicking the Quit button, as shown here:

..................Content has been hidden....................

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