Time for action – responding to the player's selection

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

  1. Create a new scene called Main Menu, with a background of blue; any blue will do as we'll be changing it later!
  2. Close the new scene.
  3. In the Dashboard tab, under Actor Types, double-click on the Stencyl Book Menu Button thumbnail to display the Animation Editor, then click on the Events button in the row of gray buttons at the upper-center of the screen.
  4. Click on + Add Event | Input | On Actor.
  5. Change the event name to Clicked.
  6. Modify the when the mouse enters Self block to when the mouse is released on Self.
  7. Add the instruction blocks to resume the game and switch to the Main Menu scene as shown in the following screenshot:
    Time for action – responding to the player's selection
  8. Repeat steps 3 through 6 for Stencyl Book Next Button; remember to stop after completing step 6, and then continue with the following steps.
  9. Double-check to ensure that the Clicked events in both the Stencyl Book Menu Button and Stencyl Book Next Button tabs state when the mouse is released on Self.
  10. Insert an unpause game block into the new event for Stencyl Book Next Button, so it looks like the following screenshot:
    Time for action – responding to the player's selection
  11. Leaving the Stencyl Book Next Button actor tab open, return to (or open, if it is closed) the Fruit Collected event of the Score Management behavior.
  12. Click-and-drag on the deactivated set Level to … block, and drop it onto the gray background as shown in the following screenshot. Note that the deactivated switch to … block will also be dragged.
    Time for action – responding to the player's selection
  13. Right-click on set Level to and select Copy.
  14. Return to the Stencyl Book Next Button actor tab, where we should see the Clicked event that we created earlier.
  15. Right-click somewhere on the gray background below the orange when the mouse is released on Self block and select Paste.
  16. Drag the newly pasted set Level to … block (the switch to … block will move with it) into the orange event block and reactivate both blocks, so the completed event looks like the following screenshot:
    Time for action – responding to the player's selection
  17. Return to the Fruit Collected event in the Score Management behavior and press the Ctrl + K keys on the keyboard (Command + K on Mac OS X) to remove the unused instruction blocks.
  18. Test the game; collect all the fruit actors on Level 1 and click on the Next button when the success banner is displayed, and then continue to complete Level 2.
  19. When Level 2 has been completed, click on the Menu button.

What just happened?

We have implemented the required instructions to enable our game to respond appropriately, based upon which button the player pressed when they completed a level.

Firstly, we created a temporary Main Menu scene, which is displayed when the player clicks on the Menu button.

The next step was to attach an event directly to the Stencyl Book Menu Button actor. We did not create a behavior and attach it to the actor, or place the instruction block in an existing behavior that was already attached to the actor. When an instruction block (or series of instruction blocks) is only relevant to a specific actor, it can be useful to attach the instructions directly to the relevant actor as an event, rather than specially creating a behavior that will only be used once. In this case, the Stencyl Book Menu Button actor is only going to be used for a single purpose—switching to the Main Menu scene. So we simply attached that instruction to the actor. We also inserted an unpause game instruction block into the Clicked event for the Stencyl Book Menu Button actor, because the Display Success Banner event that creates the success banner, pauses the game. If we don't use the unpause game instruction at this point, then the game will not function correctly when the next level starts!

We then followed a similar process for the Stencyl Book Next Button actor, but this time we copied and pasted the two required instruction blocks from the Score Management behavior's Fruit Collected event. We did this not just to save the trouble of rebuilding the two instruction blocks, but mainly because we have already tested these instructions in an earlier version of game, and we know that they work as required!

Have a go hero

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

In the previous two sections, Time for action – displaying the message and buttons and Time for action – responding to the player's selection, we implemented a system whereby, on completion of a level, the player is presented with a success message and two options: Menu and Next. We have tested the game, and we can now be confident that this newly implemented feature is working as required. However, there are some refinements that can be made to the behaviors and events that we have created:

  • Modify the required instructions in the Display Success Banner event, so that the positioning of the banner and buttons is not hardcoded; the relevant instructions should take into account the screen size.
  • Currently, when the monkey collects the last piece of fruit on each level, the fruit does not appear to have been collected, because the game pauses before the instruction to shrink the fruit has completed. Make the required modifications to the Fruit Collected event to allow time for the fruit to disappear before the success banner is displayed.
  • When the success banner is on display, the pause feature can still be activated and deactivated by pressing the P key on the keyboard. Try it! It really doesn't look very professional! The addition of a single instruction block to the Display Success Banner event can resolve this problem.

Suggested solutions to the above modifications along with comments have been implemented in the download file named 5961_07_14.stencyl.

Note

Note that the previous section (Have a go hero) tasks are optional. The game will continue to function if the above modifications are not completed.

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

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