Time for action – adding gravity to the Jungle scene

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

Gravity in a game enables actors to fall or float, depending on the configuration that we specify, and we need the gravity in our game to allow the monkey actor to fall—just as it would in a real jungle—so let's make that change to the Jungle scene:

If the Jungle tab isn't visible at the top of the screen, we'll need to open up the Jungle scene first.

  1. Click on the Dashboard tab.
  2. Click on Scenes under the RESOURCES heading in the left-hand side panel.
  3. Double-click on the thumbnail image for the Jungle scene.

Now that we can see the Jungle scene, we can change the required setting:

  1. Click on the Physics button in the row of buttons in the upper-center of the screen, as shown in the following screenshot:
    Time for action – adding gravity to the Jungle scene
  2. Change the contents of the text box next to the label Gravity (Vertical) so that it contains the number 85 as shown in the following screenshot:
    Time for action – adding gravity to the Jungle scene
  3. Click on the Test Game icon on the toolbar to save and test the game.
  4. Wait for the game to compile and display in the Flash Player window.
  5. Use the left, right, and up arrow keys to control the monkey.
  6. Try to move the monkey off the left or right edge of the scene.

What just happened?

We added gravity to our game, so now the monkey actor's behavior can do its job properly!

The Jump and Run Movement behavior needs the scene to have a gravity setting before it will work properly, because the running and jumping actions rely on the monkey being on the "ground"—which is represented by the tiles in our game.

If we have a closer look at the Physics settings on the screen, we can see that gravity can be set vertically and horizontally, which can provide some very interesting gameplay in the appropriate places!

We set the vertical gravity value to 85, because this number most closely represents the effects of real gravity on our actor, but do remember that we are only using a game physics engine—not a scientific simulation of real life!

Keeping an actor in a scene

While testing the game, it may have become apparent that there is another problem—when the monkey actor completely leaves the scene, by running off the sides, it disappears and never returns!

If that problem didn't occur during the last test, then test the game again right now, and make the monkey run off the side of the scene so that it disappears.

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

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