by Justin (Updated on 2018-11-29)
Regions are invisible areas of a Scene that detect the entry and exit of Actors. In other words, we use regions when we want to know when certain actors reach certain parts of a scene.
Suppose that you are making an adventure game.
Your hero is walking outside, and he comes across a door to a house. You want to program your game so that when your hero walks to the door, he ends up inside the house.
We want the game to detect that the hero walked on top of the door. When this happens, we want to transition to the house scene.
Regions do exactly what we want. Here's how we'd do this (going with our example scenario).
Inside the Scene Designer, place a Region.
Flip to the scene's Events page. Add a Specific Actor Enters Region event.
Fill out the event with the desired values. In our case, we want to detect when our Hero enters the Door region.
That's it! Here's a demo of the game in action. We've drawn the region for you, so you can see exactly where it is.
Regions can be created in one of two ways.
You can place a Region directly into a Scene, as we did in the demo above.
You can create a region on the fly from a Behavior or Event using a block. The block is under Scene > Regions.
If you'd like to refer to this newly created region, use the Last Created Region entry anytime you're asked to Choose Region.
Once you place a Region, you can detect when an Actor enters or exits the Region using an Event.
Alternatively, you can detect if an actor is currently inside a given region.
Troubleshooting Tip: Be sure that collisions are enabled for the actor. Regions rely on the collision system to work.
Regions come in 3 flavors: Box, Circle and Polygon.
Use the shape that best suits your game. For most games, box regions suffice.
Tip: Hold down SHIFT while placing a box region to force it to become a square.
You can move regions around to a specific (x,y) coordinate or have a region "follow" an actor, which will reposition the region around the actor's center point.
In both cases, the operation happens instantly. If you wish to have a region continually follow an actor, you must continually move the region using either of these two blocks.
The difference is that the "follow" block centers the region on the target Actor's center point.
Suppose that in an adventure game, one of the hero's special moves is a fiery barrier in which all enemies approaching him within a 100 pixel radius automatically get killed.
This could be implemented by creating a box region and having that region continually follow the Hero. When actors from the Enemy group enter this region, they get killed.
You can change the size of a Box or Circular region on the fly. Resizing uses the top-left corner as the origin.
Because boxes and circles are defined differently, you have to use the corresponding block depending on what kind of region you're working with.
If you need to reset a region's size back to its original, use the reset size of [ Region ] block. This block works on both box and circle regions.
One of the signature moves in a Mario game is the ability to enter pipes. Implement this classic mechanic, using Regions.