As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

74,786

Views

Beginner

Level

10

Comments

Events Reference

by captaincomic (Updated on 2016-01-17)


As a recap from before, 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, recall 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.

Stencyl includes a large number of events that developers can take advantage of.

 

Contents

  • Basics
  • Input
  • Time
  • Actors
  • Collisions
  • Sound
  • Attributes
  • Advanced

 

Basics

When Creating

Happens once when the Behavior is initialized.

When Drawing

All drawing code goes here. Usually happens once a frame. The difference between this and "When Updating" is that this code happens at a different time in the "game loop." As such, it is best to only perform drawing operations inside When Drawing.

When Updating

Happens for every frame of the game.

 

Input

Keyboard

Key pressed/released.

Focus

Game gains/loses focus.

Click

Mouse pressed/released/moved/dragged.

On Actor

Mouse enters/exits/presses/releases/drags on an actor.

On Region

Mouse enters/exits/presses/releases/drags on a region.

 

Time

After N seconds

Runs the code after the given delay.

Every N seconds

Runs the code every N seconds.

Pause/Unpause

Game paused/unpaused. Read our article on Pausing.

 

Actors

Created or Dies: Specific Actor

Actor is Created/Killed.

Created or Dies: Actor of Type

Actor of Type is created/killed.

Created or Dies: Member of Group

Member of group is created/killed.

Enters or Leaves the Scene or Screen: Specific Actor

Actor enters/leaves the Screen/Scene.

Enters or Leaves the Scene or Screen: Actor of Type

Actor of type enters/leaves the screen/scene.

Enters or Leaves the Scene or Screen: Member of Group

Member of group enters/leaves the screen/scene.

Enters or Leaves a Region: Specific Actor

Actors enters/leaves a Region. Read our article on Regions.

Enters or Leaves a Region: Actor of Type

Actor of type enters/leaves a region. Read our article on Regions.

Enters or Leaves a Region: Member of Group

Member of group enters/leaves a region. Read our article on Regions.

 

Collisions

This actor collides with: Something Else (Actor Type Behavior only)

Happens when this actor collides with another actor.

Any actor collides with: Specific Actor

An actor collides with another actor.

Any actor collides with: Actor of Type

An actor collides with another actor of type.

Any actor collides with: Member of Group

An actor collides with another actor of group.

Collisions Between: Type & Type

An actor of type collides with another actor of type.

Collisions Between: Group & Group

A member of group collides with another member of group.

 

Sounds

Sound is done

Sound is done. Read about Sound Playback.

Channel is done

Channel is done. Read about Sound Channels.

 

Attributes

Number

Number becomes greater/less than number.

Equality

Attribute becomes equal/not equal to attribute.

Boolean

Boolean becomes true/false.
 

 

Advanced

Custom Event

Happens when a Behavior uses the “trigger event” block (such as ‘onClick’ for button click). Similar to a function call but without parameters. Read our article on Custom Events.

Custom Block

A customizable form of ‘when [ ] happens’ that allows new blocks to be created. Read our article on Custom Blocks.

Global Custom Block

A customizable form of ‘when [ ] happens’ that allows new blocks to be created but isn’t tied to an actor or scene. Read our article on Custom Blocks.

Custom Code

Arbitrary code that lives outside of regular events. Stick in the multi-line code block (under Flow > Advanced) to use this.

Custom Import

Import statements for coders. Stick in the multi-line code block (under Flow > Advanced) to use this.

Disclaimer: 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!

10 Comments

BeeBs
Guys pls help me out on this,
I want the game to change the scene when a whole group, say for example, the whole group of "enemies" are killed, it should change the scene.
I tried the "actor of type: dies or created" event block but when I kill a sprite from the "enemies" group the scene.
Pls help me.
Thanks in advance. :)

0 3 years, 2 months ago
Chris24XD
@gatostao You can create an boolean attribute named Is Actor dead? and when the Actor is killed set it to true.
0 4 years, 4 months ago
U10Hammer
I have a problem, I can't create an event, no matter how hard I try, if it a bug or something?
-1 10 years, 4 months ago
gatostao
I have that problem with a game im doing, i used (every n seconds) to spown actor "if actor "player" is alive" but the actors keep spowning after the player is killed. Don't know how to fix this
1 12 years, 4 weeks ago
dtrungle
Should be noted:

[After N seconds] and [Every N seconds] will continue to run even when the actor it is attached to is recycled/killed.

1 12 years, 2 months ago
davient
Hopefully this will help clarify :)

Always: Activated every frame.

When Drawing: Activated when the actor/scene that the event is attached to needs redrawing. This will not happen every frame. For example if an actor is not animated and not moving.

1 12 years, 3 months ago
snortch
I agree with moltke. I would also be interested in an explanation of the difference between "always" and "when drawing".
1 12 years, 3 months ago
julianic
what about the mobile input options? those are more tricky...
-1 12 years, 5 months ago
sanescientist
I understand the "always" thing.
-1 12 years, 6 months ago
moltke
We beginners could really use some more pointers on the basics. Maybe a few examples, like illustrating the difference between "always" and "when drawing" -events.
Cheers.

1 12 years, 7 months ago

Sign In to Comment