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:
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.
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:
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.
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.
It will be helpful to know that the size of the statue is approximately 55 pixels wide and 80 pixels high.
18.222.25.112