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

Introduction to Behaviors

As a game creator, it’s not enough to add a bunch of resources to a Scene and call it a day; you have to define gameplay that will engage your players and make your game interactive.

To do this, you’ll use Stencyl’s Behavior Designer to build self-contained snippets of logic called Behaviors and attach them to your Actor Types and Scenes.
 

Note: In response to our readers, we would like to clarify that there is no associated demo/source with this article. Our apologies for the confusion!

 

Contents

  • What are Behaviors?
  • Attaching a Behavior
  • Configuring a Behavior
  • Actor Type vs. Scene Behaviors
  • Peeking under the Hood
  • What are Events?

 

What are Behaviors?

Behaviors are reusable, configurable “abilities” that you attach to Actor Types or Scenes. Together, they make up the “brains” of a game, handling all interactions that occur in the world.

Say we’re making a vertical shoot 'em up where the player controls a ship that can fire lasers.

Let’s attach a Behavior that will allow the player to fire a laser when the spacebar button is pressed.

 

Attaching a Behavior

To attach a Behavior, perform the following steps:

  1. Open the desired Actor Type (or Scene).
  2. Click the Behaviors tab.
  3. Click the Add Behavior button.
  4. Find and select the desired Behavior.
  5. Click Choose.

 

Configuring a Behavior

Behaviors can be reused and configured individually for different Actor Types or Scenes. For example, if you attach a Walking behavior to an Actor Type, you'd like to be able to configure its walking speed.

The customization occurs on the Behaviors tab, by modifying parameters called Attributes.

Let’s configure the Fire Laser Behavior for our ship Actor. First, select the Behavior you want to customize, and then fill in values for each field that’s displayed.

In this ship example, we...

  • Pick a sound effect
  • Pick a “bullet” Actor Type
  • Set the initial directions
  • Set an initial speed of 800 for the laser

Now that the Fire Laser Behavior has now been attached and configured, let's see this in action.

 

The Demo Game

(Press spacebar to fire the laser)

 

Actor Type vs. Scene Behaviors

The Behavior we created was an Actor Type Behavior and thus is available to be attached to any Actor Type (e.g., the ship).

We also have the ability to create Scene Behaviors that can get attached to any Scene. An example of this would be a "spawn" Behavior that periodically creates new enemies at the top of the screen.

 

Peeking under the Hood

Let’s take a look at a typical Behavior.

On the left you see a list of Events that can happen, and on the right, you see the response to the currently selected event. You can click on other events to display their associated responses.

We'll talk much more about what's happening on the right side later in this chapter.

 

What are Events?

Events are the building blocks of Behaviors. In short, they’re things that happen in your game that can trigger some kind of action, or response.

Returning to our vertical shoot ‘em up example, remember that when the player presses the spacebar, the player’s ship fires a laser.

In this case, hitting the spacebar is the event, and firing the laser is the response. The event and response are related by cause and effect.

 

Summary

  • Behaviors are reusable, configurable “abilities” that you attach to Actor Types or Scenes.
  • The same Behavior can be customized for multiple Actor Types or Scenes by setting Attributes.
  • Behaviors are composed of Events, which are things that happen in your game.
  • Each Event has an associated response, which determines what actions are carried out when the Event occurs.


Last Updated: 2013-01-29 by Jon

40974 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!
8 Comments
rainvillain
I don't have "Fire Laser" as one of my available Behaviors.
0 4 months, 3 days ago
Stotch
It seems like this was written as a general guideline for adding behaviors rather than as a step by step tutorial. I managed to follow along anyway by making a ship actor type and bullet actor type from the resources in Crash Course 2, creating a scene and placing the ship actor type into the scene. Then I attached the Fire Bullet behavior from the library included with Stencyl, to my ship actor, since I didn't find the Fire Laser behavior in the library. Worked same as the example except there is no sound option in the Fire Bullet behavior. I found it helpful to review Crash Course 1 to remind me how to add behaviors.
1 4 months, 1 week ago
Blacksmith
I could not find a demo to download in order to do the modifications in this and the next tutorials. The only thing on Stencylforge available was a completely finished game called Shoot Em Up (and a much much more complicated game than the examples used here).
0 10 months, 2 weeks ago
moonw
(I mean, source code empty with only the necessary things)
0 1 year, 3 weeks ago
moonw
if you download the "Shoot em Up Example" you will find that the game is already finished with lots of additional things and task already made, so I think that the source code could be necessary to beginners. Please let me know if I am in a mistake with the source code.
0 1 year, 3 weeks ago
gamecreme
at the StencylForge search for "Shoot em Up Example"
0 1 year, 1 month ago
case
Couldn't find it either but its not too necessary.
0 1 year, 1 month ago
DcSK
Hi, where is the source file?
1 1 year, 1 month 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.