Time for action – stopping the statues from becoming inactive

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

Ensure that the Manage Statues actor behavior is on screen. We should be able to see the Kill statues event. Execute the following steps to stop the statue from becoming inactive:

  1. Click on the + Add Event button at the top of the left-hand panel.
  2. Select Basics, then click on When Creating.
  3. Rename the Created event to Statues always active.
  4. Ensure that the Actor section button is selected in the instruction block palette.
  5. Click on the Properties category button.
  6. In the Misc subcategory, locate the blue make Self always active block, and drag it into the orange when created block, as shown in the following screenshot:
    Time for action – stopping the statues from becoming inactive
  7. Test the game.

What just happened?

Although our game doesn't necessarily appear to behave any differently, the statues' physics properties are now still active, even when offscreen.

We have added a new when created event to the Manage Statues behavior, and we have renamed the new event to Statues always active. A when created event is triggered only once, when the actor is first created, and it's a very useful event into which one-off configuration blocks can be placed.

Because this behavior has been attached to the statue actor, the event will be carried out once for each statue actor as it is created, and then it will never be executed again for that actor.

Inside the when created event, we placed the make Self always active block, which ensures that the actor will never become inactive, even if it is not visible in the viewport. Now we can be sure that players of our game won't experience any unexpected frozen actors.

It's important to be aware that always active actors can have a serious impact on the performance of a game if they are not used carefully. Even when active actors are offscreen, they will still react to the game's physics requirements.

For this reason, care should be taken while deciding whether or not to make an actor always active. In our scene, we know that the statues are created every three seconds, and we know that the statues are killed after six seconds (a five second delay, then a one second fade-out). So, it is impossible for more than three statues to be active in our scene at any time.

Our earlier experiments have shown that we can have up to approximately 10 to 20 statues in a scene before the game's performance is adversely affected, and we must take this into consideration if we adjust the timings in the future. For example, if we add more playable levels to our game, which are more challenging, the number of active statues in the scene may increase.

There's more than one way

When developing games, there is almost always more than one way to achieve the same result and, very often, there are many ways! It's not necessarily a case of one method being better than the others, but sometimes different solutions can affect the gameplay or the performance of the game in different ways. For example, the game might lag, or there might be other consequences of using a particular solution.

Freezing actors is an example of a problem that has more than one solution. We chose to make the statue actors always active, which is a perfectly good solution for our game. However, there is at least one other equally good solution, which can be achieved using a Scene block called set offscreen bounds to …, shown in the following screenshot:

There's more than one way

This block can be found in the Scene section blocks under the View category.

Normally, the offscreen bounds are the same size as the screen. If the actor's origin moves outside the bounds of the screen, then the actor will become inactive. However, using a set offscreen bounds to … block allows us to specify bounds beyond the edges of the screen, in which our actors can remain active.

This could be perfect for our requirements because, if we set the offscreen bounds to an appropriate size, the statues would not freeze as they left the sides of the screen, but, if the monkey moved, leaving the statue far away and outside the edges of the screen where gameplay isn't affected, the statue would become inactive. This would free up resources without affecting the gameplay.

Have a go hero – using the offscreen bounds block

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

Try replacing the make Self always active block with a set offscreen bounds to … block. Take care in deciding upon values for the arguments for this block.

Note

For detailed information relating to how to use a specific instruction block, right-click on the block and select View Help on the pop-up menu. This will open up a web browser at the relevant help page on the Stencyl website.

It will be helpful to know that the size of the statue is approximately 55 pixels wide and 80 pixels high.

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

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