28,257

Views

Beginner

Level

7

Comments

Events Reference

by Jon (Updated on 2014-01-29)


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. Web games only.

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

7 Comments

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
0 1 year, 5 months 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 1 year, 6 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 1 year, 8 months ago
snortch
I agree with moltke. I would also be interested in an explanation of the difference between "always" and "when drawing".
0 1 year, 8 months ago
julianic
what about the mobile input options? those are more tricky...
-1 1 year, 9 months ago
sanescientist
I understand the "always" thing.
-1 1 year, 11 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 1 year, 11 months ago

Sign In to Comment