Time for action – creating a behavior to drop the statues

The game file that needs to be imported and loaded for this session is 5961_04_05.stencyl.

We're going to start by creating a behavior to drop the statues into a single location in the scene, and then we'll refine the behavior as we progress. Execute the following steps in order to create a behavior to drop the statue:

  1. On the Dashboard, under the LOGIC heading, click on Scene Behaviors.
  2. Click on the message This game contains no Logic. Click here to create one. in the main panel.
  3. In the Name textbox, type Drop Actors Randomly and click on the Create button to display the behavior editor.
  4. At the top of the left-hand panel, click on + Add Event.
  5. In the pop-up menu, move the mouse over Time, then click Every N seconds (notAfter N seconds).
  6. Double-click on the Every N secs item in the left-hand panel, and change the name of the event to Drop statues.
  7. In the orange do every … seconds block, enter the digit 3 into the white textbox.
  8. Click on the Scene button at the top of the instruction block palette, as shown in the following screenshot:
    Time for action – creating a behavior to drop the statues
  9. Drag the red create Actor Type … block into the orange do every 3 seconds block.
  10. On the new red create Actor Type at … block, click on the Actor Type option and select Choose Actor Type from the drop-down menu.
  11. In the Choose an Actor Type dialog box, double-click on the icon for the Stencyl Book Statue. The red block will change to create Stencyl Book Statue at ….
  12. In the red create Stencyl Book Statue at … block, enter the number 320 into the white textbox to the right of x:.
  13. Enter the number 10 into the white textbox to the right of y:, as shown in the following screenshot:
    Time for action – creating a behavior to drop the statues
  14. Click on the green Attach to Scene button above the instruction block palette.
  15. Double-click the icon for the Jungle scene.
  16. Test the game.

What just happened?

We've created a new scene behavior that drops the statue actor into the jungle scene every 3 seconds. Rather than being attached to an actor, this behavior is attached to the scene, because the scene is going to create the statues for us.

We needed to tell the create Actor Type at … block which actor to create, and where to create it, so we selected the statue actor type in the Choose Actor Type dialog box. The numbers that we entered in the x: and y: textboxes represent the location on the screen where the statue will be created. Although we have some work to do to position the statue correctly, the numbers we provided are adequate for testing if the behavior is carrying out its main task correctly.

Note

Note that we don't need to manually add the statue actor to the jungle scene using the Scene Designer, as we have done with the monkey, fruit, and enemy actors, the create Stencyl Book Statue at … block will do all the work for us.

When we test the game, we can see that a new statue actor appears at the top-center of the screen every three seconds. However, we can quickly determine that things are not quite right. If we move the monkey, we can see that the statue is always dropping into the scene at exactly the same position, which is probably not what we're hoping for, because it won't present much of a challenge for players of our game when the monkey progresses to the other end of the scene.

Identifying and resolving problems

We've already identified one unexpected issue—the statues always fall in the same location—but it's now time to give the game a really good testing and make a note about what happens when, for example, many statues are allowed to fall into the scene. Try it.

There may be other problems to be found, but it's important to understand that these bugs aren't necessarily faults with Stencyl, they may be system limitations (that is, known features) or they could be caused by the way that we have designed the game—for example, the player's character may become stuck at a certain point in a scene if we haven't carefully considered the placing of tiles.

Sometimes these effects are desirable in a game but, if they are not, we will need to change our game so that it works differently, so it's a good idea to note any problems as early as possible (always keep a notepad and pencil at hand). It's all part of the learning process.

We'll fine-tune the behavior that drops the statues as we progress through this chapter but, before we can do that, we need to understand a little more about the relationship between screen and scene sizes.

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

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