Multiple Screens and Levels in Games
Many games have levels that the players progress through as well as title, help, and credit screens. This activity introduces some techniques to build multiple screens in your game.
Turn In: Game file named Levels-Learning.capx
Create the Levels-Learning.capx project to use for this activity.
Creating Many Layouts
Using on the upper right side of Construct2 is the Projects area that lists the items in your project. For this project, we are going to add several different layouts to our project, one layout for each screen that we want to display.
When you start a new project, the first layout is called "Layout 1" which is fine for games that only have one layout but not very intuitive for multiple layout games. In the Project window, right click on Layout 1 and pick Rename then put in Start. Right click on the Layouts folder and pick "Add layout". You are asked if you want to add event sheet, not add event sheet, or cancel. For this activity we are going to have all layouts use the same event sheet so select the option "Don't add event sheet". Rename the new layout Instructions. Add four more layouts named Level1, Level2, Level3, and Credits.
Notice that instead of the tabs Layout 1 and Event sheet 1, you have Start, Event sheet 1, Instructions, Level1, Level2, Level3, and Credits.
To help keep track of each layout we are seeing when playing the game, we will add Text with the name of the layout to each of the layouts. On the Start layout, double click in the game window then pick Text as the type of object to add. Use the name Title for the Text object then click on Insert. Click to place the Text object close to the top of the playing surface. Click inside the Text property and type in Start The Game.
Click on the Instructions tab. Do you see the Text object named Title in Objects? If not, right click inside the Projects window and pick "Filter objects" then pick "All project objects". You should see the Title object of type Text.
Drag the Title object and drop it on the Instructions layout. In the Text property put in Instructions. Do these steps for the remaining tabs and change the Text to the layer name.
Click on each of the tabs (except for Event sheet 1) and verify that they have a Text object with the name of the tab.
Moving Between Layouts
We are going to start by using the keyboard to move between layouts.
Click on the Start tab then double-click somewhere on the layout to bring up "Insert New Object". Pick Keyboard and click Insert. This will allow us to respond to keyboard events.
Click on "Event sheet 1". Add event "On key pressed" and the letter L and for the action System->Go to next/previous layout then for the Which prompt, pick next then click Done. This event will move to the next layout when the letter L is pressed.
Click on Start tab then click on the Run layout button ... you should see the layout with the Start text. Press the L key to see change to the Instructions layout. Press the L key again. It should move to the next Layout (Level1) but does not. The reason is that the Instructions layout is not connected to the Event sheet. Click on the Instructions tab then click on the white part of the layout. When you do the Layout properties display on the left side. Find the "Event sheet" property and change from (none) to "Event sheet 1". Click on each of the other tabs then the layout then change the Event sheet property from (none) to "Event sheet 1".
Click back on the Start tab then click Run layout. Press the L key to go to Instructions then L key to go to Level1, then L to go to Level2.
Note: The next layout is determined by the layout order in the Projects window. When Run layout, you will see the layout that is currently selected. Click on the Level1 tab and Run layout, you will see the Level1 layout open in the web browser.
On the "Event sheet 1", Add event "On key pressed" and the letter 1. Add action then pick System, choose "Go to layout", then pick Level1 and click Done. This says that when you press 1 on the keyboard, Level1 should appear. Run layout and verify that it works properly (be sure to start on a tab other than Level1).
On the "Event sheet 1" add an event when the S key is pressed. Add action then System and choose "Go to layout (by name)". When asked for the layout name, type in ... "Start" ... with the quotes.
Click on the Start tab. Double-click on layout and insert a new Button (in the Form Controls section). Name the button StartGame and click to place the button toward the bottom of the visible window. In the Properties of the button, change the Text from Ok to "Start Game". Stretch the button so that you see the words Start Game.
Click on "Event sheet 1" and Add event. Select the StartGame button, click Next, pick "On clicked", and pick Done. Click Add action, System, Go to Level1
Go to the Instructions tab and drag the StartGame button to that layout. Resize the button so "Start Game" is visible. Click on the Credits tab and drag the StartGame button onto the layout.
Realistic Game Play
Click on the Level1 tab. Double-click to add a button and name it ScorePoints. Click on Insert and click on the layout to place the button. Change the text of the button to Points.
Click on "Event sheet 1". Right click and add a global variable named Points as a number with the value of 0. Add event and pick the ScorePoints button and "On click" then Done. Add action then System and the action "Add to". Click Next. Pick Points for the variable and put in 10 for the Value. Click Done.
Right now, when on Level1 and you click the Points button, the Points global variable is increased by 10.
In some games, you move from level 1 to level 2 when a certain point level is reached. In our game, we are going to level 2 when we have 100 points.
On "Event sheet 1", Add event and pick System then "Compare variable" and click Next. Choose the Variable Points, Comparison of "Greater or equal", and Value of 100. Click Done.
Add action and pick System then "Set value". Click Next. Variable Points and Value of 0. This resets the points back to 0. Then add another action for this event which is the System->Go to the layout Level2.
Click on the Start tab and Run layout. Click on the "Start Game" button. Click on the Points button at least 10 times to move to level 2.
Copyright © 2021 Eric Schumm. Permission granted to freely use this in your classroom.