Time for action – creating the pause framework

The game file to import and load for this session is 5961_07_08.stencyl.

  1. Locate and download the actor called Stencyl Book Paused Banner from StencylForge.
  2. When the Stencyl Book Paused Banner actor has downloaded, click on the Physics button in the row of buttons at the upper-center of the screen.
  3. In the General section, which is currently displayed in the main panel, change the What kind of actor type? setting to Cannot Move.
  4. Click on the Advanced icon at the top of the panel, and change the Can be Paused? setting to No.
  5. Close the tabs for the Stencyl Book Paused Banner actor and StencylForge.
  6. Create a new scene behavior called Pause Management.
  7. Using the green Attach to Scene button at the upper-right corner of the screen, add the new behavior to the scene called Level1.
  8. Switch back to the Pause Management behavior, then repeat step 7, attaching the behavior to Level2 and Level3 (but not Level4, which is the yellow, completed scene).
  9. Close the tabs for Level1, Level2, and Level3.
  10. In the new Pause Management behavior, create an actor attribute called Paused Banner, by clicking on the Attributes section button in the block palette, then the Create an Attribute… button below the category buttons. Ensure that the new attribute is configured with Type as Actor as shown in the following screenshot:
    Time for action – creating the pause framework
  11. Add a new when created event to the Pause Management behavior and rename it to Create Pause Banner.
  12. Add the required blocks to the newly created when created event, as shown in the following screenshot:
    Time for action – creating the pause framework
  13. Do not test the game yet; we have some more work to do before the pause feature is ready!

What just happened?

We have put in place the framework for placing a pause message on the screen.

The first step was to download the Paused Banner actor from StencylForge; when we add the instructions for pausing the game, this message banner will be displayed so players of our game will have a clear indication that the game has been paused. Because we do not want the banner to move under any circumstances, we configured its What kind of actor type? setting to Cannot Move. Because by default, all actors are configured to pause when the game is paused, we have specified that the banner cannot be paused. This will ensure that the banner is displayed correctly when all the other actors in the scene have been paused.

We then created a new scene behavior called Pause Management, and we attached it to the three existing game levels, but not the scene named Level4. In the previous Have a go hero section, it was suggested that only one additional level should be added in order to avoid additional work later in the development process. Because we are still developing our game, we will almost certainly be adding additional scene behaviors that will be required for each of the game levels, and when we do add those behaviors, we must remember to add them to each and every level that already exists in the game. For this reason, it's a good idea to leave the design and creation of additional levels until the development process has been finalized. This allows us to simply duplicate existing levels along with all the behaviors that are attached to the original scene.

However, because we already have three levels in our game, the next step was to attach the new Pause Management behavior to each of those levels. We could have done this after completing the design of the events in this behavior, but it's a good idea to attach it as soon as the behavior has been created, so that we don't forget to do it at a later stage!

The next step was to create an actor attribute called Paused Banner, and this attribute will be used to store the instance of the Stencyl Book Paused Banner actor that we have just created, so that we can access it easily from any other events with the Pause Management behavior. We'll be accessing this attribute in the when created event.

We then added the required instructions to the when created event. The first block creates an instance of the Stencyl Book Paused Banner actor with an x and y position of zero.

The second instruction in the when created event, set Paused Banner to Last Created Actor, sets the value of the Paused Banner actor attribute that we created earlier, to the value of Last Created Actor, which must be the newly created Stencyl Book Paused Banner, because that actor was created in the immediately-preceding instruction block! This ensures that, as long as the scene is active, we can always easily refer to the banner using the Paused Banner actor attribute; without this attribute, it would be very difficult to access and make changes to the banner.

We then inserted an instruction to hide the banner actor that we just created; this ensures that it cannot be seen by the player when the scene is first displayed. Note that we have just hidden the banner actor, so it cannot be seen; we have not killed it, so we can now manipulate it as required!

Implementing the pause feature

Now that we have the framework in place, we can create the main pause routine.

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

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