Construct 2 Tutorial – Destroy Outside Layout Behavior

Construct 2 Tutorial – Destroy Outside Layout Behavior


The next Behavior we’re going to discuss,
is probably the easiest to use out of all the Behaviors. But, that doesn’t mean it isn’t as useful. In fact, it is one of the most important Behaviors
to understand, if you are concerned about your game’s performance. The Destroy Outside of Layout Behavior does
one thing, it Destroys an object, as soon as the object leaves the layout. There are no parameters, no actions, no expressions,
it simply destroys an object when it leaves the layout. Why is this so important, though? Well, imagine if you have a space shooter. On the screen is the player’s ship, and
it can shoot bullets. Then, enemies are spawned, and each of them
shoot bullets. Before you know it, there are tons of enemies
who have left the layout, each still shooting bullets. The computer still calculates the speed, angles,
position, collisions, etc, for every single object, even if it’s outside of the layout. Once a bullet leaves the layout, it will never
be useful again. There is no reason for the user’s computer
to continually calculate it’s position, speed, etc… This layout is setup with a tower cannon,
and a bullet object, with the Bullet Behavior applied. I’ve set up an event, so when you press
the space bar, a bullet is spawned at the tip of the cannon. Let’s take a look. When I press space, a new bullet is spawned,
and travels off to the right of the screen. Let’s look at that again, but this time,
I’ll click Debug Layout, right next to Preview Layout. With Debug Layout, we can see a list of each
instance of an object, and all of the information we have about that object. If I click on Bullet, this number zero is
the single instance of the bullet, that I drug off the top of the layout. You can see it’s current X position here,
constantly rising, as it flies endlessly outside of the layout. If I press space, and fire the cannon, each
Bullet that’s fired will be listed here. If I select one of them, you can see it’s
X position being calculated every frame, even though this bullet is far outside of the layout,
and will never be used in game again. I’ll select the bullet, click on Behaviors,
Add New, and select Destroy Outside Layout, under General. If I Debug the layout again, you
can see, there are no instances of the Bullet object. The sole instance of it, which was outside the layout,
was immediately destroyed. If I shoot the cannon a few times, you can
see the Bullet instances that are added to the layout, but as they leave the layout,
they are removed from the list, as they get destroyed. If I shoot as fast as I can, I can only get
about 7 bullets spawned at any one time. That’s much less taxing on the system,
than having hundreds of bullets flying off into nothingness for the duration of the level. As you can see, Destroy Outside Layout is
not a hard Behavior to understand, but it is an essential Behavior to have added to
your toolbox. By utilizing this behavior when necessary,
you will drastically improve the performance of your games. Thanks for watching. If you found this content helpful, please consider supporting me on Patreon. Comment, like, and share this video, and subscribe for more tutorials. See you next time.

2 thoughts on “Construct 2 Tutorial – Destroy Outside Layout Behavior

  1. thanks for this tutz, very helpful.wish you do the behavior CUSTOM MOVEMENT next with example. Been looking around for an example of this behavior on the net but haven't found any.

  2. i really appreciate your sharing , thank you so much , could we create a dame or chess by contruct 2 ?

Leave a Reply

Your email address will not be published. Required fields are marked *