Username or E-mail
Password (Forgot?)
New? Sign Up
Join or Sign In
Forums Stencylpedia Stencyl TV Translations Go Pro - Plans & Pricing Download Stencyl


Switch to Book Layout

1: Getting Started

  • Getting Started
  • Crash Course
  • Crash Course 2
  • StencylForge

2: Building Logic

  • What is a Behavior?
  • Creating a Behavior
  • Attributes
  • Game Attributes
  • Attribute Types
  • Events
  • Our Behaviors

3: Actors

  • What are Actors?
  • Animations
  • Motion & Forces
  • Physics
  • Controls
  • Collisions & Groups
  • Killing vs. Recycling
  • Tweening
  • Effects
  • Chapter 3 Challenge

4: Scenes

  • Scene Basics
  • The Camera
  • Tilesets
  • Regions
  • Drawing Text & HUDs
  • Changing Scenes
  • Music, Sounds & Channels
  • Backgrounds
  • Customizing Actors
  • Chapter 4 Challenge

5: Game Mechanics

  • Saving
  • Pausing
  • 3rd Party Services
  • Web Requests

6: Advanced Topics

  • Get/Set Attributes
  • Custom Events
  • Blending Modes
  • Lists
  • Custom Blocks
  • Continuous Collisions

7: Testing & Tuning

  • Testing Games
  • Optimizing Performance 1
  • Optimizing Performance 2

8: The Last 10%

  • Flash Publishing
  • Standalone Apps
  • iOS App Store
  • Chrome Store
  • Making Money

M1: Mobile - Intro

  • Getting Started
  • Testing on your Device
  • Flash -> iOS Guide

M2: Mobile - Basics

  • Atlases
  • Drawing Text
  • Retina Display
  • Accelerometer
  • Joystick
  • Universal Games

M3: Mobile - Services

  • iAds
  • Game Center
  • In-App Purchases

M4: Mobile - Publishing

  • Debugging
  • Publishing to the App Store
  • Optimizing Performance
  • Promoting your Game

A: Troubleshooting

  • Showstoppers
  • General FAQ
  • iOS FAQ
  • The 90% Memory Warning
  • Recovering Broken Games
  • Can't Export to SWF
  • Reloading Documents
  • Generating Logs
  • Flash Security Settings
  • How to Report Bugs

B: How-To Guides

  • Importing Assets
  • Scene Designer
  • Code Mode
  • Font Editor
  • Pencyl (Image Editor)
  • Tile Editor (Shapes)
  • Game Cleaner

C: Reference

  • Glossary
  • Block Reference
  • Useful Shortcuts
  • Stencyl API

D: Resources

  • Stencyl TV
  • Abigayl's Guides
  • Giving Critiques
  • Creating Extensions
  • Translating Stencyl
  • Credits

3.0 Drafts (In Progress)

  • What's New in Stencyl 3.0?
  • Setup (Android)
  • Setup (Desktop)
  • Setup (iOS) - Concepts
  • Setup (iOS) - Mac
  • Setup (iOS) - Windows
  • Testing iOS on Windows
  • iOS Troubleshooter

  • Mobile App Scaling
  • Full Screen Mode
  • Simple Physics
  • Backgrounding an App

  • iOS App Store
  • Mac App Store
  • Windows Store
  • Google Play
  • HTML5

  • Android Ads
  • Android Purchases (WIP)
  • 4" Form Factor (iPhone 5)
  • Mobile Input
  • Mobile Features

  • Extending the Engine
  • iOS / Android Extensions
  • Developing the Official Extensions
  • Developing the Engine

  • iAds (Revised)
  • Game Center (Revised)
  • iOS Purchases (Revised)
  • Atlases (Revised)
  • Drawing Text (Revised)
  • Joystick (Revised)
  • Accelerometer (Revised)
  • Sounds (Revised, WIP)
  • Debugging (Revised, WIP)
  • iOS Performance (Revised)
Level: Beginner

Regions

Contents

  • What are Regions?
  • Example: Entering a Door
  • Creating Regions
  • Detecting Entry/Exit
  • Region Types
  • Moving Regions
  • Resizing Regions

 

What are Regions?

Regions are invisible areas of a Scene that detect the entry and exit of Actors.

In plain speak, we use regions when we want to know when certain actors reach certain parts of a scene.


In what situations would regions be useful?

  •     Entering doors, pipes and other transportation devices
  •     Entering an area that continually heals the player (Healing Zone)
  •     Entering an area that continually harms the player (Lava Zone)
  •     Stepping on a switch
  •     And more...

 

Example: Entering a Door

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.

How would you do this?

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 (going with our example scenario).

1) Inside the Scene Designer, place the Region.

2) Flip to the Events page. Add a “Specific Actor Enters Region” event.

3) Fill out the event with the desired values. In our case, we want to detect when our Hero enters the Door region.

4) Finally, we add in the scene switch block (Scene > Game Flow) to change the scene.


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.


Creating Regions

Regions can be created in one of two ways.

1) You can place a Region directly into a Scene, as we did in the demo above.


2) You can create a region on the fly from a Behavior or Event. 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.

 

Detecting Actors entering, exiting or being inside Regions

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.


What’s the difference?

    Event = I entered the house.
    Is Inside = Are you currently inside your house?


Region Types

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.


Moving Regions

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.

 

Example: Fiery Barrier

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.

(Play the Demo)

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.

 

Resizing Regions

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 resize block. This block works on both box and circle regions.


Summary

  • Regions tell us when actors have reached certain parts of a scene.
  • You can detect when an actor enters, exits or is currently inside a region.
  • You can create regions either by placing them in the scene or creating them from a behavior.
  • You can move and resize regions.

 

Challenge: Pipes!

It’s a me, Mario! One of the signature moves in a Mario game is the ability to enter pipes. Implement this classic mechanic, using Regions.

 



Last Updated: 2012-03-30 by Jon

16687 have read this article
Disclaimer: The Stencyl Team does not actively monitor comments on articles. If you're seeking help for your game, please ask a question on the forums. Thanks!
4 Comments
t4u
IMPORTANT: you need to have collisions ON inorder to be able to detect ifactor is / enters the region
0 6 months, 2 weeks ago
Vectrex71
Ahh i guess, the polygon regions are not available for mobile projects (right?)
0 12 months, 1 day ago
Vectrex71
I use stencil 2.1 but i can't find polygon regions?! i only have circle and box !
0 12 months, 4 days ago
HarkBack
And about 'terrain' there is an article?
1 1 year, 3 weeks ago



Commenting Guidelines

Sign In to Comment

Make Games

  • What is Stencyl?
  • Roadmap
  • Pricing

Play

  • Arcade
  • Showcase

Community

  • Forums
  • Chat
  • Translations

Help

  • Stencylpedia
  • Stencyl TV

About Us

  • Blog
  • Contact Us
  • Press
  • Privacy
Follow Stencyl on Twitter



© 2013 Stencyl, LLC.