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.
Happens once when the Behavior is initialized.
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.
Happens for every frame of the game.
Game gains/loses focus.
Mouse enters/exits/presses/releases/drags on an actor.
Mouse enters/exits/presses/releases/drags on a region.
After N seconds
Runs the code after the given delay.
Every N seconds
Runs the code every N seconds.
Game paused/unpaused. Read our article on Pausing.
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.
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.
Sound is done
Sound is done. Read about Sound Playback.
Channel is done
Channel is done. Read about Sound Channels.
Number becomes greater/less than number.
Attribute becomes equal/not equal to attribute.
Boolean becomes true/false.
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.
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.
Arbitrary code that lives outside of regular events. Stick in the multi-line code block (under Flow > Advanced) to use this.
Import statements for coders. Stick in the multi-line code block (under Flow > Advanced) to use this.
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. :)
@gatostao You can create an boolean attribute named Is Actor dead? and when the Actor is killed set it to true.
I have a problem, I can't create an event, no matter how hard I try, if it a bug or something?
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
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.
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.
I agree with moltke. I would also be interested in an explanation of the difference between "always" and "when drawing".
what about the mobile input options? those are more tricky...
I understand the "always" thing.
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.