34,841

Views

Beginner

Level

4

Comments

What are Actors?

by Jon (Updated on 2013-01-29)


This article introduces you to the key concepts behind actors, without getting into much detail. Because Actor concepts are intertwined, it's useful to get a little exposure to each before delving into full detail.

 

Contents

  • What are Actors?
  • Appearance
  • Behaviors
  • Collisions (Physics)
  • Actor Types and Instances


What are Actors?

Actors represent the living, interactive part of a game. Actors are the players, enemies, projectiles, vehicles, inteface elements and anything in a game that "lives."

[Insert Image of several different actors]

Every actor can be broken up into a few common elements.

  • Appearance - How the actor looks or appears in-game.
  • Behavior - How the actor behaves or acts.
  • Physics - How the actor interacts with the world when it collides with it. This also determines what shape(s) the actor takes on, whether it's a box, a circle or something else.

 

Appearance

Appearance dictates how an Actor looks. In the 2D games we build, this means Animations.

Animations are a collection of frames that are played out in sequence and usually loop, to form a fluid, living visual representation of the actor.

Actors need not be bound to a single animation. They can switch between different states, each which are associated with their own Animation and collision bounds.

More concretely, consider the hero character in a platformer such as Mario. This character will have states for standing, walking, running and jumping.

Note: Coming from Scratch? Animation States are called costumes over there.


Further Reading: We go into much further detail about Animations and States later in this chapter.


Behaviors

Behaviors tell an actor what to do and how to react. They provide specific logic which allows the actor to perform unique tasks like run, jump, walk, fire weapon and more.

Behaviors are unique in that they are reusable and configurable.

  • Reusable: They can be attached to other actors. (Example: Attach a Fire spell behavior to other actors)


     
  • Configurable: You can configure their Attributes (properties) (Example: Set the walking speed)


Events

You may notice an "Events" page when opening up the Actor Editor. This page lets you attach Events directly to an actor, without requiring a full behavior.

This is useful for adding logic that's specific to the actor and great for rapid prototyping.

Note: Events are new to Stencyl 2.0. In the past, we found that our users would create Behaviors just for one particular Actor Type, which cluttered up their projects.


Further Reading: We don't cover the Behaviors or Events pages in Chapter 3, since you got exposed to plenty of that already in Chapter 2. For a refresher, read Chapter 2's introduction.

 

Collisions (Physics)

In many games, Actors collide with other Actors, In our engine, our Actors obey the laws of physics and act much like real-world objects.

In order to make this all happen, the Actors need to assume a physical form, whether it's a box, a circle, a polygon or some combination of those.

These physical forms are known as Collision Bounds, and they are tied directly to Animation States. Intuitively, this makes sense. If your character stands, he takes on one shape. If he's "ducking" on the ground, his shape will be shorter.


Sensors

Sensors allow collisions to occur without generating a physical reaction. This is useful when you don't want a certain Actor to "push" other actors away but do want that collision to happen.

For example, slashing a sword or being hit by a fireball shouldn't always knock you back, but it should definitely hurt.

 

Groups

Groups let you filter collisions, so that only certain classes of Actors collide with each other.

To take a real-life example, consider the concept of "friendly fire" - sometimes, you don't want your enemy's bullets to kill other enemies. Groups let you prevent this from happening.

 

Physical Properties

As mentioned earlier, Actors obey the laws of physics. The Physics page lets you tweak an actor's physical attributes that don't pertain to its collision bounds.

Here are just some of the properties you can tweak.

  • Whether an actor moves, rotates or obeys gravity.
  • Mass
  • Friction
  • Bounciness
  • Damping

 

Further Reading: We cover Collisions & Groups in a separate article, and Physical Properties in its own article too.

 

Actor Types vs. Instances

Two terms you may see thrown around are Actor Types and Actor Instances. More confusingly, we may abbreviate both to simply "Actor", with no indication, outside of context, which of the two we're talking about.

The difference is this: Actor Types are like templates or prototypes, while instances are the actual "Actors" that exist inside a scene.

 

Example: Goombas

Consider a game like Super Mario Bros. A Goomba is a common enemy in this game. We expect Goombas to look like this:

And we expect them to act in the same way, namely to walk in one direction until they hit a wall, then reverse direction.

But every instance of Goomba exists at a different location on the scene. When you step on one, it dies. These are each separate instances of Goomba.

This, in a gist is the distinction between an Actor Type and Actor Instance.

Programmers' Note: Types are akin to Classes, while Instances are akin to Objects.

 

Summary

  • Actors are the things that make a game come to life. In simple terms, they are the "objects" or "props"
  • Actors can take on different Animation States, each with their own Animation and Collision Bounds.
  • You can control how an Actor acts by attaching Behaviors or Events.
  • Actors obey the laws of physics. You can tweak an Actor's physical properties such as whether it can move, its mass and friction.
Disclaimer: All articles are geared towards Stencyl 3.0 and above. Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

4 Comments

Picky
I have a trouble, how can I make static objects?
1 7 months, 1 day ago
alex2013
I saved the game and now what should I do to continue the game?

2 1 year, 1 month ago
Takarashi282
Typo under "Collisions (Physics)": 'If he's "ducking" on the ground, his shape will llikely be shorter'
*likely
These are wonderful examples by the way.

0 1 year, 11 months ago
snortch
nice use of examples here Jon.
1 2 years, 3 weeks ago

Sign In to Comment