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.
10 Comments
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
@gatostao You can create an boolean attribute named Is Actor dead? and when the Actor is killed set it to true.
0
I have a problem, I can't create an event, no matter how hard I try, if it a bug or something?
-1
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
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
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
I agree with moltke. I would also be interested in an explanation of the difference between "always" and "when drawing".
1
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